Skip to content

Commit 2d98a60

Browse files
Display when competition is full
1 parent 540ef67 commit 2d98a60

File tree

5 files changed

+89
-24
lines changed

5 files changed

+89
-24
lines changed

server.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ def index():
3434

3535
@app.route('/showSummary', methods=['POST'])
3636
def showSummary():
37-
club = [club for club in clubs if club['email'] == request.form['email']][
38-
0]
39-
return render_template('welcome.html', club=club,
40-
competitions=competitions)
37+
try:
38+
club = [club for club in clubs if club['email'] == request.form['email']][
39+
0]
40+
return render_template('welcome.html', club=club,
41+
competitions=competitions)
42+
except IndexError:
43+
flash('Wrong email-please try again')
44+
return render_template('index.html')
4145

4246

4347
@app.route('/book/<competition>/<club>')

templates/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,15 @@ <h1>Welcome to the GUDLFT Registration Portal!</h1>
1212
<input type="email" name="email" id=""/>
1313
<button type="submit">Enter</button>
1414
</form>
15+
16+
17+
{% with messages = get_flashed_messages()%}
18+
{% if messages %}
19+
{% for message in messages %}
20+
{{message}}
21+
{% endfor %}
22+
{% endif %}
23+
{% endwith %}
24+
1525
</body>
1626
</html>

templates/welcome.html

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@
77
<body>
88
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
99

10-
{% with messages = get_flashed_messages()%}
10+
{% with messages = get_flashed_messages() %}
1111
{% if messages %}
1212
<ul>
1313
{% for message in messages %}
1414
<li>{{message}}</li>
1515
{% endfor %}
1616
</ul>
1717
{% endif%}
18-
Points available: {{club['points']}}
18+
Points available: {{ club['points'] }}
1919
<h3>Competitions:</h3>
2020
<ul>
21-
{% for comp in competitions%}
21+
{% for comp in competitions %}
2222
<li>
23-
{{comp['name']}}<br />
24-
Date: {{comp['date']}}</br>
25-
Number of Places: {{comp['numberOfPlaces']}}
26-
{%if comp['numberOfPlaces']|int >0%}
27-
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
28-
{%endif%}
23+
<p>{{ comp['name'] }}</p>
24+
<p>Date: {{ comp['date'] }}</p>
25+
<p>Number of Places: {{ comp['numberOfPlaces'] }}</p>
26+
{% if comp['numberOfPlaces']|int >0 %}
27+
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
28+
{% else %}
29+
<span>- Competition complete</span>
30+
{% endif %}
2931
</li>
30-
<hr />
32+
<hr>
3133
{% endfor %}
3234
</ul>
33-
{%endwith%}
35+
{% endwith %}
3436

3537
</body>
3638
</html>

tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import copy
21
import pytest
32
import json
43

5-
from server import app
4+
from server import app, competitions
65

76

87
@pytest.fixture
@@ -22,3 +21,12 @@ def test_clubs():
2221
def test_competitions():
2322
with open('competitions.json') as comps:
2423
return json.load(comps)['competitions']
24+
25+
26+
@pytest.fixture
27+
def test_competition_full():
28+
competitions[:] = [
29+
{'name': 'Spring Festival',
30+
'date': '2020-03-27 10:00:00',
31+
'numberOfPlaces': '0'}
32+
]

tests/test_server.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
from server import loadCompetitions, loadClubs
33

44

5-
def test_purchase_places(client):
6-
test_club = loadClubs()[0]
7-
test_competition = loadCompetitions()[0]
5+
def test_purchase_places(client, test_clubs, test_competitions, mocker):
6+
mocker.patch('server.loadClubs', return_value=test_clubs)
7+
mocker.patch('server.loadCompetitions', return_value=test_competitions)
8+
mock_save_club = mocker.patch('server.saveClub')
9+
10+
mocker.patch.object(server, 'clubs', test_clubs)
11+
mocker.patch.object(server, 'competitions', test_competitions)
812
places_to_purchase = 8
913

1014
response = client.post('/purchasePlaces', data={
11-
'club': test_club['name'],
12-
'competition': test_competition['name'],
15+
'club': test_clubs[0]['name'],
16+
'competition': test_competitions[0]['name'],
1317
'places': places_to_purchase
1418
})
1519

@@ -47,8 +51,7 @@ def test_has_sufficient_points(client):
4751
assert b'Insufficiant points.' in response.data
4852

4953

50-
def test_purchase_places(client, test_clubs, test_competitions, mocker):
51-
54+
def test_update_points_after_purchase(client, test_clubs, test_competitions, mocker):
5255
mocker.patch('server.loadClubs', return_value=test_clubs)
5356
mocker.patch('server.loadCompetitions', return_value=test_competitions)
5457
mock_save_club = mocker.patch('server.saveClub')
@@ -66,3 +69,41 @@ def test_purchase_places(client, test_clubs, test_competitions, mocker):
6669

6770
assert int(test_clubs[0]['points']) == 4
6871
assert b'Great-booking complete!' in response.data
72+
73+
74+
def test_login(client):
75+
76+
response = client.post('/showSummary', data={
77+
'email': 'john@simplylift.co'
78+
})
79+
assert response.status_code == 200
80+
81+
82+
def test_wrong_login(client):
83+
84+
response = client.post('/showSummary', data={
85+
'email': 'wrong-email@test.com'
86+
})
87+
assert response.status_code == 200
88+
assert b'Wrong email-please try again' in response.data
89+
90+
91+
def test_display_book_available(client):
92+
test_club = loadClubs()[0]
93+
test_competitions = loadCompetitions()
94+
95+
response = client.post('/showSummary', data={'email': test_club['email']})
96+
97+
assert response.status_code == 200
98+
assert b'Number of Places: 25' in response.data
99+
100+
101+
def test_display_book_non_available(client, test_competition_full):
102+
103+
test_club = loadClubs()[0]
104+
105+
response = client.post('/showSummary', data={'email': test_club['email']})
106+
107+
assert response.status_code == 200
108+
assert b'Spring Festival' in response.data
109+
assert b'- Competition complete' in response.data

0 commit comments

Comments
 (0)