Skip to content

Fixed purchase when insufficiant club points #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024
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 @@ -60,6 +60,11 @@ def purchasePlaces():
return render_template('welcome.html', club=club,
competitions=competitions)

if placesRequired > int(club['points']):
flash('Insufficiant points.')
return render_template('welcome.html', club=club,
competitions=competitions)

competition['numberOfPlaces'] = int(
competition['numberOfPlaces']) - placesRequired
flash('Great-booking complete!')
Expand Down
30 changes: 20 additions & 10 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

def test_purchase_places(client):

clubs = loadClubs()
competitions = loadCompetitions()

test_club = clubs[0]
test_competition = competitions[0]
test_club = loadClubs()[0]
test_competition = loadCompetitions()[0]
places_to_purchase = 8

response = client.post('/purchasePlaces', data={
Expand All @@ -22,11 +19,8 @@ def test_purchase_places(client):

def test_max_purchase_places(client):

clubs = loadClubs()
competitions = loadCompetitions()

test_club = clubs[0]
test_competition = competitions[0]
test_club = loadClubs()[0]
test_competition = loadCompetitions()[0]
places_to_purchase = 28

response = client.post('/purchasePlaces', data={
Expand All @@ -37,3 +31,19 @@ def test_max_purchase_places(client):

assert response.status_code == 200
assert b'Max purchase 12.' in response.data


def test_has_sufficient_points(client):

test_club = loadClubs()[1]
test_competition = loadCompetitions()[0]
places_to_purchase = 9

response = client.post('/purchasePlaces', data={
'club': test_club['name'],
'competition': test_competition['name'],
'places': places_to_purchase
})

assert response.status_code == 200
assert b'Insufficiant points.' in response.data