Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
18 changes: 17 additions & 1 deletion tests/test_purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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'