From 8e52a4781542ee8f63df7b44bf537fe4cd5198e6 Mon Sep 17 00:00:00 2001 From: devogs Date: Mon, 8 Sep 2025 12:52:01 +0200 Subject: [PATCH 1/2] FEAT: Add TDD test for 12-place booking limit --- tests/test_purchase.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_purchase.py b/tests/test_purchase.py index 13d38354e..8024fbb98 100644 --- a/tests/test_purchase.py +++ b/tests/test_purchase.py @@ -47,4 +47,20 @@ def test_purchase_with_sufficient_points_and_places_without_save(client): assert b'Welcome' in response.data # Verify that the points and places were updated in the mock data assert mock_clubs[0]['points'] == '5' - assert mock_competitions[0]['numberOfPlaces'] == 15 \ No newline at end of file + assert mock_competitions[0]['numberOfPlaces'] == 15 + + +def test_purchase_more_than_max_places(client): + """Test that a club cannot book more than 12 places per competition.""" + with patch('server.clubs', [{'name': 'Test Club', 'email': 'test@test.com', 'points': '20'}]): + with patch('server.competitions', [{'name': 'Test Competition', 'numberOfPlaces': '20'}]): + with patch('server.flash') as mock_flash: + response = client.post('/purchasePlaces', data={ + 'club': 'Test Club', + 'competition': 'Test Competition', + 'places': '13' + }, follow_redirects=False) + + mock_flash.assert_called_once_with("You cannot book more than 12 places per competition.") + assert response.status_code == 302 + assert response.location == '/book/Test%20Competition/Test%20Club' From 17f337bcab3d73397b4122151eb5fb53b3ac1b6e Mon Sep 17 00:00:00 2001 From: devogs Date: Mon, 8 Sep 2025 12:52:30 +0200 Subject: [PATCH 2/2] FIX: Implement 12-place booking limit --- server.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server.py b/server.py index 23881016e..5debb0fc9 100644 --- a/server.py +++ b/server.py @@ -56,6 +56,11 @@ def purchasePlaces(): club = [c for c in clubs if c['name'] == request.form['club']][0] placesRequired = int(request.form['places']) + # FIX for Bug 3: Block bookings over 12 places + if placesRequired > 12: + flash("You cannot book more than 12 places per competition.") + return redirect(url_for('book', competition=competition['name'], club=club['name'])) + # Check if club has enough points if int(club['points']) < placesRequired: flash(f"You do not have enough points to book {placesRequired} places. You currently have {club['points']} points.")