diff --git a/clubs.json b/clubs.json
index 1d7ad1ffe..d2432dc98 100644
--- a/clubs.json
+++ b/clubs.json
@@ -1,16 +1,19 @@
-{"clubs":[
+{
+ "clubs": [
{
- "name":"Simply Lift",
- "email":"john@simplylift.co",
- "points":"13"
+ "name": "Simply Lift",
+ "email": "john@simplylift.co",
+ "points": "13"
},
{
- "name":"Iron Temple",
- "email": "admin@irontemple.com",
- "points":"4"
+ "name": "Iron Temple",
+ "email": "admin@irontemple.com",
+ "points": "4"
},
- { "name":"She Lifts",
- "email": "kate@shelifts.co.uk",
- "points":"12"
+ {
+ "name": "She Lifts",
+ "email": "kate@shelifts.co.uk",
+ "points": "12"
}
-]}
\ No newline at end of file
+ ]
+}
\ No newline at end of file
diff --git a/server.py b/server.py
index e220e4eb1..3ec357c97 100644
--- a/server.py
+++ b/server.py
@@ -9,7 +9,6 @@ def loadClubs():
def saveClub(clubs):
-
with open('clubs.json', 'w') as c:
json.dump({'clubs': clubs}, c)
@@ -32,10 +31,19 @@ def index():
return render_template('index.html')
+@app.route('/clubs-points')
+def clubs_points():
+ return render_template(
+ 'clubs-points.html',
+ clubs=clubs
+ )
+
+
@app.route('/showSummary', methods=['POST'])
def showSummary():
try:
- club = [club for club in clubs if club['email'] == request.form['email']][
+ club = \
+ [club for club in clubs if club['email'] == request.form['email']][
0]
return render_template('welcome.html', club=club,
competitions=competitions)
@@ -60,7 +68,8 @@ def book(competition, club):
@app.route('/purchasePlaces', methods=['POST'])
def purchasePlaces():
competition = \
- [c for c in competitions if c['name'] == request.form['competition']][0]
+ [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'])
diff --git a/templates/clubs-points.html b/templates/clubs-points.html
new file mode 100644
index 000000000..0b9dd4ed8
--- /dev/null
+++ b/templates/clubs-points.html
@@ -0,0 +1,26 @@
+
+
+
+
+ Clubs points || GUDLFT
+
+
+ Clubs points
+
+ {% if clubs %}
+
+
+ Name | Points |
+
+ {% for club in clubs %}
+ {{ club['name'] }} | {{ club['points'] }} |
+ {% endfor %}
+
+
+
+ {% endif %}
+
+ Back
+
+
+
\ No newline at end of file
diff --git a/tests/conftest.py b/tests/conftest.py
index 5a3c904e9..dce3d9e15 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,6 +1,7 @@
import pytest
import json
+import server
from server import app, competitions
@@ -13,20 +14,29 @@ def client():
@pytest.fixture
def test_clubs():
- with open('clubs.json') as c:
+ with open('tests/test_clubs.json') as c:
return json.load(c)['clubs']
@pytest.fixture
def test_competitions():
- with open('competitions.json') as comps:
+ with open('tests/test_competitions.json') as comps:
return json.load(comps)['competitions']
@pytest.fixture
def test_competition_full():
competitions[:] = [
- {'name': 'Spring Festival',
+ {'name': 'Test Comptetition #3',
'date': '2020-03-27 10:00:00',
'numberOfPlaces': '0'}
]
+
+
+@pytest.fixture
+def setup_mocks(mocker, test_clubs, test_competitions):
+ mocker.patch('server.loadClubs', return_value=test_clubs)
+ mocker.patch('server.loadCompetitions', return_value=test_competitions)
+ mocker.patch('server.saveClub')
+ mocker.patch.object(server, 'clubs', test_clubs)
+ mocker.patch.object(server, 'competitions', test_competitions)
diff --git a/tests/test_clubs.json b/tests/test_clubs.json
new file mode 100644
index 000000000..c5a2f3679
--- /dev/null
+++ b/tests/test_clubs.json
@@ -0,0 +1,19 @@
+{
+ "clubs": [
+ {
+ "name": "Test club #1",
+ "email": "john@test.com",
+ "points": "13"
+ },
+ {
+ "name": "Test club #2",
+ "email": "admin@test.com",
+ "points": "4"
+ },
+ {
+ "name": "Test club #3",
+ "email": "kate@test.com",
+ "points": "12"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/tests/test_competitions.json b/tests/test_competitions.json
new file mode 100644
index 000000000..e0022d2a5
--- /dev/null
+++ b/tests/test_competitions.json
@@ -0,0 +1,14 @@
+{
+ "competitions": [
+ {
+ "name": "Test Competition #1",
+ "date": "2020-03-27 10:00:00",
+ "numberOfPlaces": "25"
+ },
+ {
+ "name": "Test Competition #2",
+ "date": "2020-10-22 13:30:00",
+ "numberOfPlaces": "13"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/tests/test_server.py b/tests/test_server.py
index c66074ba0..80d582092 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -1,14 +1,7 @@
-import server
-from server import loadCompetitions, loadClubs
+from server import loadClubs
-def test_purchase_places(client, test_clubs, test_competitions, mocker):
- mocker.patch('server.loadClubs', return_value=test_clubs)
- mocker.patch('server.loadCompetitions', return_value=test_competitions)
- mock_save_club = mocker.patch('server.saveClub')
-
- mocker.patch.object(server, 'clubs', test_clubs)
- mocker.patch.object(server, 'competitions', test_competitions)
+def test_purchase_places(client, test_clubs, test_competitions, setup_mocks):
places_to_purchase = 8
response = client.post('/purchasePlaces', data={
@@ -21,14 +14,12 @@ def test_purchase_places(client, test_clubs, test_competitions, mocker):
assert b'Great-booking complete!' in response.data
-def test_max_purchase_places(client):
- test_club = loadClubs()[0]
- test_competition = loadCompetitions()[0]
+def test_max_purchase_places(client, test_clubs, test_competitions, setup_mocks):
places_to_purchase = 28
response = client.post('/purchasePlaces', data={
- 'club': test_club['name'],
- 'competition': test_competition['name'],
+ 'club': test_clubs[0]['name'],
+ 'competition': test_competitions[0]['name'],
'places': places_to_purchase
})
@@ -36,14 +27,12 @@ def test_max_purchase_places(client):
assert b'Max purchase 12.' in response.data
-def test_has_sufficient_points(client):
- test_club = loadClubs()[1]
- test_competition = loadCompetitions()[0]
+def test_has_sufficient_points(client, test_clubs, test_competitions, setup_mocks):
places_to_purchase = 9
response = client.post('/purchasePlaces', data={
- 'club': test_club['name'],
- 'competition': test_competition['name'],
+ 'club': test_clubs[1]['name'],
+ 'competition': test_competitions[0]['name'],
'places': places_to_purchase
})
@@ -51,14 +40,7 @@ def test_has_sufficient_points(client):
assert b'Insufficiant points.' in response.data
-def test_update_points_after_purchase(client, test_clubs, test_competitions, mocker):
- mocker.patch('server.loadClubs', return_value=test_clubs)
- mocker.patch('server.loadCompetitions', return_value=test_competitions)
- mock_save_club = mocker.patch('server.saveClub')
-
- mocker.patch.object(server, 'clubs', test_clubs)
- mocker.patch.object(server, 'competitions', test_competitions)
-
+def test_update_points_after_purchase(client, test_clubs, test_competitions, setup_mocks):
places_to_purchase = 9
response = client.post('/purchasePlaces', data={
@@ -89,8 +71,8 @@ def test_wrong_login(client):
def test_display_book_available(client):
+
test_club = loadClubs()[0]
- test_competitions = loadCompetitions()
response = client.post('/showSummary', data={'email': test_club['email']})
@@ -105,5 +87,10 @@ def test_display_book_non_available(client, test_competition_full):
response = client.post('/showSummary', data={'email': test_club['email']})
assert response.status_code == 200
- assert b'Spring Festival' in response.data
assert b'- Competition complete' in response.data
+
+
+def test_display_points_table(client):
+
+ response = client.get('/clubs-points')
+ assert response.status_code == 200