Skip to content

Commit 6c9f55c

Browse files
committed
fix: prevent clubs from redeeming more points than available
1 parent 2c215e7 commit 6c9f55c

4 files changed

Lines changed: 58 additions & 4 deletions

File tree

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
filterwarnings =
3+
ignore::DeprecationWarning

server.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ def purchasePlaces():
4646
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
4747
club = [c for c in clubs if c['name'] == request.form['club']][0]
4848
placesRequired = int(request.form['places'])
49-
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
50-
flash('Great-booking complete!')
51-
return render_template('welcome.html', club=club, competitions=competitions)
49+
50+
point_club = int(club['points'])
51+
if point_club < placesRequired:
52+
flash('You are not authorized to book this number of places!')
53+
return render_template('welcome.html', club=club, competitions=competitions)
54+
else:
55+
flash('Great-booking complete!')
56+
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
57+
return render_template('welcome.html', club=club, competitions=competitions)
5258

5359

5460
# TODO: Add route for points display

templates/welcome.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<title>Summary | GUDLFT Registration</title>
66
</head>
77
<body>
8-
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
8+
<h2>Welcome, {{club['email']}}
9+
</h2><a href="{{url_for('logout')}}">Logout</a>
910

1011
{% with messages = get_flashed_messages()%}
1112
{% if messages %}
@@ -15,7 +16,9 @@ <h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
1516
{% endfor %}
1617
</ul>
1718
{% endif%}
19+
1820
Points available: {{club['points']}}
21+
1922
<h3>Competitions:</h3>
2023
<ul>
2124
{% for comp in competitions%}

test/test_server.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
def test_show_summary_with_valid_email(client):
2+
response = client.post("/showSummary", data={
3+
"email": "admin@irontemple.com"
4+
})
5+
6+
assert response.status_code == 200
7+
assert b"Welcome" in response.data
8+
9+
def test_show_summary_with_unknown_email(client):
10+
response = client.post("/showSummary", data={
11+
"email": "unknown@test.com"
12+
}, follow_redirects=True)
13+
14+
assert response.status_code == 200
15+
assert b"Sorry, that email was not found" in response.data
16+
17+
18+
19+
20+
def test_purchase_places_with_valid_number_of_places(client):
21+
response = client.post("/purchasePlaces", data={
22+
"competition": "Spring Festival",
23+
"club": "Iron Temple",
24+
"places": "2"
25+
}, follow_redirects=True)
26+
27+
assert response.status_code == 200
28+
assert b"Great-booking complete!" in response.data
29+
30+
def test_purchase_places_with_too_many_places(client):
31+
response = client.post("/purchasePlaces", data={
32+
"competition": "Spring Festival",
33+
"club": "Iron Temple",
34+
"places": "5",
35+
})
36+
37+
assert response.status_code == 200
38+
assert b"You are not authorized to book this number of places" in response.data
39+
40+
41+
42+

0 commit comments

Comments
 (0)