Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattgris6 committed Nov 16, 2022
1 parent 81e09c8 commit cc5a695
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ 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'])
if placesRequired > int(club["points"]):
flash(f'You did not have enought points : only {club["points"]} were booked.')
placesRequired = int(club["points"])
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/unit/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions tests/unit/test_purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

import server

@pytest.fixture
def client():
with server.app.test_client() as client:
yield client

@pytest.fixture
def club():
one_club = server.clubs[0]
one_club["points"] = 4
return one_club['name']

@pytest.fixture
def competition():
return server.competitions[0]['name']

class TestPurchase:
def test_purchase_too_many_places(self, client, club, competition):
"""Checks response when authenticated user request"""
response = client.post(
"/purchasePlaces",
data={'places':8, 'club':club, 'competition':competition},
follow_redirects=True
)
assert response.status_code == 200
data = response.data.decode()
assert data.find("You did not have enought points") != -1
assert data.find("Great-booking complete!") != -1

def test_purchase_legal_number_places(self, client, club, competition):
"""Checks response when authenticated user request"""
response = client.post(
"/purchasePlaces",
data={'places':4, 'club':club, 'competition':competition},
follow_redirects=True
)
assert response.status_code == 200
data = response.data.decode()
assert data.find("Great-booking complete!") != -1
assert data.find("You did not have enought points") == -1

0 comments on commit cc5a695

Please sign in to comment.