Skip to content

Added public display of points #7

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 2 commits into from
Jul 17, 2024
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
25 changes: 14 additions & 11 deletions clubs.json
Original file line number Diff line number Diff line change
@@ -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"
}
]}
]
}
15 changes: 12 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def loadClubs():


def saveClub(clubs):

with open('clubs.json', 'w') as c:
json.dump({'clubs': clubs}, c)

Expand All @@ -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)
Expand All @@ -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'])
Expand Down
26 changes: 26 additions & 0 deletions templates/clubs-points.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clubs points || GUDLFT</title>
</head>
<body>
<h2>Clubs points</h2>

{% if clubs %}

<table border="1">
<thead><tr><th>Name</th><th>Points</th></tr></thead>
<tbody>
{% for club in clubs %}
<tr><td>{{ club['name'] }}</td><td>{{ club['points'] }}</td></tr>
{% endfor %}
</tbody>
</table>

{% endif %}

<a href="{{ url_for('index') }}">Back</a>

</body>
</html>
16 changes: 13 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import json

import server
from server import app, competitions


Expand All @@ -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)
19 changes: 19 additions & 0 deletions tests/test_clubs.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
14 changes: 14 additions & 0 deletions tests/test_competitions.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
45 changes: 16 additions & 29 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -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={
Expand All @@ -21,44 +14,33 @@ 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
})

assert response.status_code == 200
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
})

assert response.status_code == 200
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={
Expand Down Expand Up @@ -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']})

Expand All @@ -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