Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Aponovi committed May 30, 2022
1 parent ff20903 commit ccd9761
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from flask import Flask, render_template, request, redirect, flash, url_for

POINTS_FOR_A_PLACE = 1

def loadClubs():
with open('clubs.json') as c:
Expand Down Expand Up @@ -52,11 +53,15 @@ 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!')
places_allowed = int(club["points"]) // POINTS_FOR_A_PLACE
if placesRequired > places_allowed:
flash(f"You cannot book more than {places_allowed} place(s), due to the number of points held.")
else:
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
club["points"] = places_allowed - placesRequired * POINTS_FOR_A_PLACE
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)


# TODO: Add route for points display


Expand Down
25 changes: 25 additions & 0 deletions tests/units/test_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from server import POINTS_FOR_A_PLACE


class TestLoginClass:
def test_login_email_known(self, client, mock_competitions_and_clubs):
response = client.post('/showSummary', data={"email": "test@club.com"})
Expand All @@ -8,3 +11,25 @@ def test_login_email_unknown(self, client, mock_competitions_and_clubs):
response = client.post('/showSummary', data={"email": "unkown@email.com"})
assert response.status_code == 200
assert "Sorry, that email wasn't found." in response.data.decode()


class TestPurchaseClass:
def test_purchase_places(self, client, mock_competitions_and_clubs):
response = client.post('/purchasePlaces', data={'club': 'Test Club',
'competition': 'Spring Festival',
'places': 2
}
)
expected_value = 13-(2 * POINTS_FOR_A_PLACE)
assert response.status_code == 200
assert "Great-booking complete" in response.data.decode()
assert f"Points available: {expected_value}"

def test_purchase_more_than_the_points(self, client, mock_competitions_and_clubs):
response = client.post('/purchasePlaces', data={'club': 'Last Test Club',
'competition': 'Spring Festival',
'places': 5
}
)
assert response.status_code == 200
assert "cannot book" in response.data.decode()

0 comments on commit ccd9761

Please sign in to comment.