diff --git a/server.py b/server.py index 90525ff87..0e21b7c48 100644 --- a/server.py +++ b/server.py @@ -47,10 +47,15 @@ def book(competition,club): 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.get("points")): + flash('You haven\'t enough of points to purshase this!') + return render_template('welcome.html', club=club, competitions=competitions), 403 + competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired flash('Great-booking complete!') - return render_template('welcome.html', club=club, competitions=competitions) + return render_template('welcome.html', club=club, competitions=competitions), 200 # TODO: Add route for points display diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index 7bd2cb951..c66721c19 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -1,9 +1,9 @@ import pytest from unittest.mock import patch - import server + def get_clubs(): return [ { diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index ef2c372fa..97fe9e0c6 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -25,4 +25,17 @@ def test_sould_connect_with_email_exists(self): def test_sould_no_connect_with_email_does_not_exists(self): response = self.client.post("/showSummary", data={'email': "not_exists_email@test.com"}) - assert response.status_code == 401 + self.assertEqual(response.status_code, 401) + + def test_sould_not_purshase_more_than_I_own(self): + for com in self.competitions: + for cl in self.clubs: + mock = { + "club": cl.get('name'), + "competition": com.get('name'), + "places": int(cl.get('points')) + 1 + } + + response = self.client.post('/purchasePlaces', data=mock) + self.assertIn("You haven't enough of points to purshase this!", response.data.decode()) + self.assertEqual(response.status_code, 403)