Skip to content

Bug/ fix club points update #250

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib
.Python
tests/
.envrc
__pycache__
__pycache__
pyvenv.cfg
3 changes: 2 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def purchasePlaces():
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places'])
club['points'] = int(club['points']) - placesRequired
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)
Expand All @@ -56,4 +57,4 @@ def purchasePlaces():

@app.route('/logout')
def logout():
return redirect(url_for('index'))
return redirect(url_for('index'))
42 changes: 42 additions & 0 deletions tests/unit/test_purchase_places.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
import os
import pytest
sys.path.insert(
0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../')
)
)

from server import app, clubs, competitions # noqa


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


def test_purchase_places_updates_club_points(client):
club = next(c for c in clubs if c['name'] == 'Simply Lift')
competition = next(
c for c in competitions if c['name'] == 'Spring Festival'
)

initial_points = int(club['points'])
initial_places = int(competition['numberOfPlaces'])
places_to_purchase = 3

response = client.post('/purchasePlaces', data={
'competition': 'Spring Festival',
'club': 'Simply Lift',
'places': places_to_purchase
})

assert b"Great-booking complete!" in response.data

updated_points = initial_points - places_to_purchase
assert int(club['points']) == updated_points

updated_places = initial_places - places_to_purchase
assert int(competition['numberOfPlaces']) == updated_places