Skip to content

Commit 0e3df6e

Browse files
Merge pull request #2 from githubstevemas/bugfix/purchase-with-insufficiant-points
Fixed purchase when insufficiant club points
2 parents 6db6b83 + 3da7f19 commit 0e3df6e

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def purchasePlaces():
6060
return render_template('welcome.html', club=club,
6161
competitions=competitions)
6262

63+
if placesRequired > int(club['points']):
64+
flash('Insufficiant points.')
65+
return render_template('welcome.html', club=club,
66+
competitions=competitions)
67+
6368
competition['numberOfPlaces'] = int(
6469
competition['numberOfPlaces']) - placesRequired
6570
flash('Great-booking complete!')

tests/test_server.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
def test_purchase_places(client):
55

6-
clubs = loadClubs()
7-
competitions = loadCompetitions()
8-
9-
test_club = clubs[0]
10-
test_competition = competitions[0]
6+
test_club = loadClubs()[0]
7+
test_competition = loadCompetitions()[0]
118
places_to_purchase = 8
129

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

2320
def test_max_purchase_places(client):
2421

25-
clubs = loadClubs()
26-
competitions = loadCompetitions()
27-
28-
test_club = clubs[0]
29-
test_competition = competitions[0]
22+
test_club = loadClubs()[0]
23+
test_competition = loadCompetitions()[0]
3024
places_to_purchase = 28
3125

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

3832
assert response.status_code == 200
3933
assert b'Max purchase 12.' in response.data
34+
35+
36+
def test_has_sufficient_points(client):
37+
38+
test_club = loadClubs()[1]
39+
test_competition = loadCompetitions()[0]
40+
places_to_purchase = 9
41+
42+
response = client.post('/purchasePlaces', data={
43+
'club': test_club['name'],
44+
'competition': test_competition['name'],
45+
'places': places_to_purchase
46+
})
47+
48+
assert response.status_code == 200
49+
assert b'Insufficiant points.' in response.data

0 commit comments

Comments
 (0)