Skip to content

Bug/ fix limit booking to 12 places per competition #253

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

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
31 changes: 23 additions & 8 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,34 @@ def book(competition,club):
return render_template('welcome.html', club=club, competitions=competitions)


@app.route('/purchasePlaces',methods=['POST'])
@app.route('/purchasePlaces', methods=['POST'])
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'])
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)
competition = next(
(c for c in competitions if c['name'] == request.form['competition']),
None
)
club = next((c for c in clubs if c['name'] == request.form['club']), None)
places_required = int(request.form['places'])

if places_required > 12:
flash("You cannot book more than 12 places in a single competition.")
return render_template(
'welcome.html', club=club, competitions=competitions
), 200

club['points'] = str(int(club['points']) - places_required)
competition['numberOfPlaces'] = str(
int(competition['numberOfPlaces']) - places_required
)
flash('Great - booking complete!')
return render_template(
'welcome.html', club=club, competitions=competitions
)


# TODO: Add route for points display


@app.route('/logout')
def logout():
return redirect(url_for('index'))
return redirect(url_for('index'))
48 changes: 48 additions & 0 deletions tests/unit/test_purchase_places.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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_exceeds_max_limit(client):
response = client.post('/purchasePlaces', data={
'competition': 'Spring Festival',
'club': 'Simply Lift',
'places': 13
})

assert b"You cannot book more than 12 places in a single competition." \
in response.data

competition = next(
c for c in competitions if c['name'] == 'Spring Festival'
)
assert competition['numberOfPlaces'] == "25"


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

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

competition = next(
c for c in competitions if c['name'] == 'Spring Festival'
)
assert competition['numberOfPlaces'] == "13"