From fab4e6667d73b674ea4e79e569db18ff493cdbee Mon Sep 17 00:00:00 2001 From: Julien Denizot Date: Wed, 6 Nov 2024 15:05:31 +0100 Subject: [PATCH 1/2] Fix club points deduction after booking --- .gitignore | 3 ++- server.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2cba99d87..e2d7aa6dc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ lib .Python tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +pyvenv.cfg diff --git a/server.py b/server.py index 4084baeac..d7b1500b1 100644 --- a/server.py +++ b/server.py @@ -46,6 +46,7 @@ def purchasePlaces(): competition = [c for c in competitions if c['name'] == request.form['competition']][0] club = [c for c in clubs if c['name'] == request.form['club']][0] placesRequired = int(request.form['places']) + club['points'] = int(club['points']) - placesRequired competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired flash('Great-booking complete!') return render_template('welcome.html', club=club, competitions=competitions) @@ -56,4 +57,4 @@ def purchasePlaces(): @app.route('/logout') def logout(): - return redirect(url_for('index')) \ No newline at end of file + return redirect(url_for('index')) From d663144188356afc9e7f860d7ef06b7bd43ef403 Mon Sep 17 00:00:00 2001 From: Julien Denizot Date: Wed, 13 Nov 2024 10:16:36 +0100 Subject: [PATCH 2/2] Add test to verify club points update after successful booking --- tests/unit/test_purchase_places.py | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/unit/test_purchase_places.py diff --git a/tests/unit/test_purchase_places.py b/tests/unit/test_purchase_places.py new file mode 100644 index 000000000..62078dc71 --- /dev/null +++ b/tests/unit/test_purchase_places.py @@ -0,0 +1,42 @@ +import sys +import os +import pytest +sys.path.insert( + 0, os.path.abspath( + os.path.join(os.path.dirname(__file__), '../../') + ) +) + +from server import app, clubs, competitions # noqa + + +@pytest.fixture +def client(): + app.config['TESTING'] = True + with app.test_client() as client: + yield client + + +def test_purchase_places_updates_club_points(client): + club = next(c for c in clubs if c['name'] == 'Simply Lift') + competition = next( + c for c in competitions if c['name'] == 'Spring Festival' + ) + + initial_points = int(club['points']) + initial_places = int(competition['numberOfPlaces']) + places_to_purchase = 3 + + response = client.post('/purchasePlaces', data={ + 'competition': 'Spring Festival', + 'club': 'Simply Lift', + 'places': places_to_purchase + }) + + assert b"Great-booking complete!" in response.data + + updated_points = initial_points - places_to_purchase + assert int(club['points']) == updated_points + + updated_places = initial_places - places_to_purchase + assert int(competition['numberOfPlaces']) == updated_places