Skip to content

Bug/clubs should not be able to use more than their points allowed #2

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

Merged
Merged
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
7 changes: 6 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from unittest.mock import patch


import server


def get_clubs():
return [
{
Expand Down
15 changes: 14 additions & 1 deletion tests/unit_test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)