Skip to content

Commit 540ef67

Browse files
Merge pull request #3 from githubstevemas/bugfix/update-available-club-point-after-purchase
Fixed update available club point after purchase
2 parents 0e3df6e + 17287a6 commit 540ef67

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

server.py

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def loadClubs():
88
return listOfClubs
99

1010

11+
def saveClub(clubs):
12+
13+
with open('clubs.json', 'w') as c:
14+
json.dump({'clubs': clubs}, c)
15+
16+
1117
def loadCompetitions():
1218
with open('competitions.json') as comps:
1319
listOfCompetitions = json.load(comps)['competitions']
@@ -65,8 +71,12 @@ def purchasePlaces():
6571
return render_template('welcome.html', club=club,
6672
competitions=competitions)
6773

74+
club['points'] = str(int(club['points']) - placesRequired)
75+
saveClub(clubs)
76+
6877
competition['numberOfPlaces'] = int(
6978
competition['numberOfPlaces']) - placesRequired
79+
7080
flash('Great-booking complete!')
7181

7282
return render_template('welcome.html', club=club,

tests/conftest.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
import copy
12
import pytest
3+
import json
24

3-
from server import app, loadClubs, loadCompetitions
5+
from server import app
46

57

68
@pytest.fixture
79
def client():
810
app.config['TESTING'] = True
911
with app.test_client() as client:
1012
yield client
13+
14+
15+
@pytest.fixture
16+
def test_clubs():
17+
with open('clubs.json') as c:
18+
return json.load(c)['clubs']
19+
20+
21+
@pytest.fixture
22+
def test_competitions():
23+
with open('competitions.json') as comps:
24+
return json.load(comps)['competitions']

tests/test_server.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import server
12
from server import loadCompetitions, loadClubs
23

34

45
def test_purchase_places(client):
5-
66
test_club = loadClubs()[0]
77
test_competition = loadCompetitions()[0]
88
places_to_purchase = 8
@@ -18,7 +18,6 @@ def test_purchase_places(client):
1818

1919

2020
def test_max_purchase_places(client):
21-
2221
test_club = loadClubs()[0]
2322
test_competition = loadCompetitions()[0]
2423
places_to_purchase = 28
@@ -34,7 +33,6 @@ def test_max_purchase_places(client):
3433

3534

3635
def test_has_sufficient_points(client):
37-
3836
test_club = loadClubs()[1]
3937
test_competition = loadCompetitions()[0]
4038
places_to_purchase = 9
@@ -47,3 +45,24 @@ def test_has_sufficient_points(client):
4745

4846
assert response.status_code == 200
4947
assert b'Insufficiant points.' in response.data
48+
49+
50+
def test_purchase_places(client, test_clubs, test_competitions, mocker):
51+
52+
mocker.patch('server.loadClubs', return_value=test_clubs)
53+
mocker.patch('server.loadCompetitions', return_value=test_competitions)
54+
mock_save_club = mocker.patch('server.saveClub')
55+
56+
mocker.patch.object(server, 'clubs', test_clubs)
57+
mocker.patch.object(server, 'competitions', test_competitions)
58+
59+
places_to_purchase = 9
60+
61+
response = client.post('/purchasePlaces', data={
62+
'club': test_clubs[0]['name'],
63+
'competition': test_competitions[0]['name'],
64+
'places': str(places_to_purchase)
65+
})
66+
67+
assert int(test_clubs[0]['points']) == 4
68+
assert b'Great-booking complete!' in response.data

0 commit comments

Comments
 (0)