Skip to content

Fixed update available club point after purchase #3

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
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
10 changes: 10 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def loadClubs():
return listOfClubs


def saveClub(clubs):

with open('clubs.json', 'w') as c:
json.dump({'clubs': clubs}, c)


def loadCompetitions():
with open('competitions.json') as comps:
listOfCompetitions = json.load(comps)['competitions']
Expand Down Expand Up @@ -65,8 +71,12 @@ def purchasePlaces():
return render_template('welcome.html', club=club,
competitions=competitions)

club['points'] = str(int(club['points']) - placesRequired)
saveClub(clubs)

competition['numberOfPlaces'] = int(
competition['numberOfPlaces']) - placesRequired

flash('Great-booking complete!')

return render_template('welcome.html', club=club,
Expand Down
16 changes: 15 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import copy
import pytest
import json

from server import app, loadClubs, loadCompetitions
from server import app


@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as client:
yield client


@pytest.fixture
def test_clubs():
with open('clubs.json') as c:
return json.load(c)['clubs']


@pytest.fixture
def test_competitions():
with open('competitions.json') as comps:
return json.load(comps)['competitions']
25 changes: 22 additions & 3 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import server
from server import loadCompetitions, loadClubs


def test_purchase_places(client):

test_club = loadClubs()[0]
test_competition = loadCompetitions()[0]
places_to_purchase = 8
Expand All @@ -18,7 +18,6 @@ def test_purchase_places(client):


def test_max_purchase_places(client):

test_club = loadClubs()[0]
test_competition = loadCompetitions()[0]
places_to_purchase = 28
Expand All @@ -34,7 +33,6 @@ def test_max_purchase_places(client):


def test_has_sufficient_points(client):

test_club = loadClubs()[1]
test_competition = loadCompetitions()[0]
places_to_purchase = 9
Expand All @@ -47,3 +45,24 @@ def test_has_sufficient_points(client):

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


def test_purchase_places(client, test_clubs, test_competitions, mocker):

mocker.patch('server.loadClubs', return_value=test_clubs)
mocker.patch('server.loadCompetitions', return_value=test_competitions)
mock_save_club = mocker.patch('server.saveClub')

mocker.patch.object(server, 'clubs', test_clubs)
mocker.patch.object(server, 'competitions', test_competitions)

places_to_purchase = 9

response = client.post('/purchasePlaces', data={
'club': test_clubs[0]['name'],
'competition': test_competitions[0]['name'],
'places': str(places_to_purchase)
})

assert int(test_clubs[0]['points']) == 4
assert b'Great-booking complete!' in response.data