Skip to content

Commit 6ab9a66

Browse files
Merge pull request #7 from githubstevemas/feature/public-display-points-table
Added public display of points
2 parents acf85f6 + dcf9168 commit 6ab9a66

File tree

7 files changed

+114
-46
lines changed

7 files changed

+114
-46
lines changed

clubs.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
{"clubs":[
1+
{
2+
"clubs": [
23
{
3-
"name":"Simply Lift",
4-
"email":"john@simplylift.co",
5-
"points":"13"
4+
"name": "Simply Lift",
5+
"email": "john@simplylift.co",
6+
"points": "13"
67
},
78
{
8-
"name":"Iron Temple",
9-
"email": "admin@irontemple.com",
10-
"points":"4"
9+
"name": "Iron Temple",
10+
"email": "admin@irontemple.com",
11+
"points": "4"
1112
},
12-
{ "name":"She Lifts",
13-
"email": "kate@shelifts.co.uk",
14-
"points":"12"
13+
{
14+
"name": "She Lifts",
15+
"email": "kate@shelifts.co.uk",
16+
"points": "12"
1517
}
16-
]}
18+
]
19+
}

server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def loadClubs():
99

1010

1111
def saveClub(clubs):
12-
1312
with open('clubs.json', 'w') as c:
1413
json.dump({'clubs': clubs}, c)
1514

@@ -32,10 +31,19 @@ def index():
3231
return render_template('index.html')
3332

3433

34+
@app.route('/clubs-points')
35+
def clubs_points():
36+
return render_template(
37+
'clubs-points.html',
38+
clubs=clubs
39+
)
40+
41+
3542
@app.route('/showSummary', methods=['POST'])
3643
def showSummary():
3744
try:
38-
club = [club for club in clubs if club['email'] == request.form['email']][
45+
club = \
46+
[club for club in clubs if club['email'] == request.form['email']][
3947
0]
4048
return render_template('welcome.html', club=club,
4149
competitions=competitions)
@@ -60,7 +68,8 @@ def book(competition, club):
6068
@app.route('/purchasePlaces', methods=['POST'])
6169
def purchasePlaces():
6270
competition = \
63-
[c for c in competitions if c['name'] == request.form['competition']][0]
71+
[c for c in competitions if c['name'] == request.form['competition']][
72+
0]
6473
club = [c for c in clubs if c['name'] == request.form['club']][0]
6574

6675
placesRequired = int(request.form['places'])

templates/clubs-points.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<html lang="en">
2+
<head>
3+
<meta charset="UTF-8">
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<title>Clubs points || GUDLFT</title>
6+
</head>
7+
<body>
8+
<h2>Clubs points</h2>
9+
10+
{% if clubs %}
11+
12+
<table border="1">
13+
<thead><tr><th>Name</th><th>Points</th></tr></thead>
14+
<tbody>
15+
{% for club in clubs %}
16+
<tr><td>{{ club['name'] }}</td><td>{{ club['points'] }}</td></tr>
17+
{% endfor %}
18+
</tbody>
19+
</table>
20+
21+
{% endif %}
22+
23+
<a href="{{ url_for('index') }}">Back</a>
24+
25+
</body>
26+
</html>

tests/conftest.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import json
33

4+
import server
45
from server import app, competitions
56

67

@@ -13,20 +14,29 @@ def client():
1314

1415
@pytest.fixture
1516
def test_clubs():
16-
with open('clubs.json') as c:
17+
with open('tests/test_clubs.json') as c:
1718
return json.load(c)['clubs']
1819

1920

2021
@pytest.fixture
2122
def test_competitions():
22-
with open('competitions.json') as comps:
23+
with open('tests/test_competitions.json') as comps:
2324
return json.load(comps)['competitions']
2425

2526

2627
@pytest.fixture
2728
def test_competition_full():
2829
competitions[:] = [
29-
{'name': 'Spring Festival',
30+
{'name': 'Test Comptetition #3',
3031
'date': '2020-03-27 10:00:00',
3132
'numberOfPlaces': '0'}
3233
]
34+
35+
36+
@pytest.fixture
37+
def setup_mocks(mocker, test_clubs, test_competitions):
38+
mocker.patch('server.loadClubs', return_value=test_clubs)
39+
mocker.patch('server.loadCompetitions', return_value=test_competitions)
40+
mocker.patch('server.saveClub')
41+
mocker.patch.object(server, 'clubs', test_clubs)
42+
mocker.patch.object(server, 'competitions', test_competitions)

tests/test_clubs.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"clubs": [
3+
{
4+
"name": "Test club #1",
5+
"email": "john@test.com",
6+
"points": "13"
7+
},
8+
{
9+
"name": "Test club #2",
10+
"email": "admin@test.com",
11+
"points": "4"
12+
},
13+
{
14+
"name": "Test club #3",
15+
"email": "kate@test.com",
16+
"points": "12"
17+
}
18+
]
19+
}

tests/test_competitions.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"competitions": [
3+
{
4+
"name": "Test Competition #1",
5+
"date": "2020-03-27 10:00:00",
6+
"numberOfPlaces": "25"
7+
},
8+
{
9+
"name": "Test Competition #2",
10+
"date": "2020-10-22 13:30:00",
11+
"numberOfPlaces": "13"
12+
}
13+
]
14+
}

tests/test_server.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import server
2-
from server import loadCompetitions, loadClubs
1+
from server import loadClubs
32

43

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)
4+
def test_purchase_places(client, test_clubs, test_competitions, setup_mocks):
125
places_to_purchase = 8
136

147
response = client.post('/purchasePlaces', data={
@@ -21,44 +14,33 @@ def test_purchase_places(client, test_clubs, test_competitions, mocker):
2114
assert b'Great-booking complete!' in response.data
2215

2316

24-
def test_max_purchase_places(client):
25-
test_club = loadClubs()[0]
26-
test_competition = loadCompetitions()[0]
17+
def test_max_purchase_places(client, test_clubs, test_competitions, setup_mocks):
2718
places_to_purchase = 28
2819

2920
response = client.post('/purchasePlaces', data={
30-
'club': test_club['name'],
31-
'competition': test_competition['name'],
21+
'club': test_clubs[0]['name'],
22+
'competition': test_competitions[0]['name'],
3223
'places': places_to_purchase
3324
})
3425

3526
assert response.status_code == 200
3627
assert b'Max purchase 12.' in response.data
3728

3829

39-
def test_has_sufficient_points(client):
40-
test_club = loadClubs()[1]
41-
test_competition = loadCompetitions()[0]
30+
def test_has_sufficient_points(client, test_clubs, test_competitions, setup_mocks):
4231
places_to_purchase = 9
4332

4433
response = client.post('/purchasePlaces', data={
45-
'club': test_club['name'],
46-
'competition': test_competition['name'],
34+
'club': test_clubs[1]['name'],
35+
'competition': test_competitions[0]['name'],
4736
'places': places_to_purchase
4837
})
4938

5039
assert response.status_code == 200
5140
assert b'Insufficiant points.' in response.data
5241

5342

54-
def test_update_points_after_purchase(client, test_clubs, test_competitions, mocker):
55-
mocker.patch('server.loadClubs', return_value=test_clubs)
56-
mocker.patch('server.loadCompetitions', return_value=test_competitions)
57-
mock_save_club = mocker.patch('server.saveClub')
58-
59-
mocker.patch.object(server, 'clubs', test_clubs)
60-
mocker.patch.object(server, 'competitions', test_competitions)
61-
43+
def test_update_points_after_purchase(client, test_clubs, test_competitions, setup_mocks):
6244
places_to_purchase = 9
6345

6446
response = client.post('/purchasePlaces', data={
@@ -89,8 +71,8 @@ def test_wrong_login(client):
8971

9072

9173
def test_display_book_available(client):
74+
9275
test_club = loadClubs()[0]
93-
test_competitions = loadCompetitions()
9476

9577
response = client.post('/showSummary', data={'email': test_club['email']})
9678

@@ -105,5 +87,10 @@ def test_display_book_non_available(client, test_competition_full):
10587
response = client.post('/showSummary', data={'email': test_club['email']})
10688

10789
assert response.status_code == 200
108-
assert b'Spring Festival' in response.data
10990
assert b'- Competition complete' in response.data
91+
92+
93+
def test_display_points_table(client):
94+
95+
response = client.get('/clubs-points')
96+
assert response.status_code == 200

0 commit comments

Comments
 (0)