Compare commits
11 Commits
main
...
bug/issue5
Author | SHA1 | Date | |
---|---|---|---|
ada3a5cc76 | |||
e089e78fc5 | |||
1009e35d17 | |||
7521a05db9 | |||
364bdb3d9f | |||
0345e8e8df | |||
e6d4d05917 | |||
5102e366e8 | |||
b70f80f3cb | |||
2317006de9 | |||
a50d1946ce |
@ -13,4 +13,4 @@
|
||||
"email": "kate@shelifts.co.uk",
|
||||
"points":"12"
|
||||
}
|
||||
]}
|
||||
]}
|
||||
|
@ -7,7 +7,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Fall Classic",
|
||||
"date": "2020-10-22 13:30:00",
|
||||
"date": "2025-10-22 13:30:00",
|
||||
"numberOfPlaces": "13"
|
||||
}
|
||||
]
|
||||
|
51
server.py
51
server.py
@ -1,5 +1,6 @@
|
||||
import json
|
||||
from flask import Flask,render_template,request,redirect,flash,url_for
|
||||
from flask import Flask,render_template,request,redirect,flash,url_for,session
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def loadClubs():
|
||||
@ -19,6 +20,8 @@ app.secret_key = 'something_special'
|
||||
|
||||
competitions = loadCompetitions()
|
||||
clubs = loadClubs()
|
||||
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
@ -26,19 +29,26 @@ def index():
|
||||
|
||||
@app.route('/showSummary',methods=['POST'])
|
||||
def showSummary():
|
||||
club = [club for club in clubs if club['email'] == request.form['email']][0]
|
||||
return render_template('welcome.html',club=club,competitions=competitions)
|
||||
|
||||
club = [club for club in clubs if club['email'] == request.form['email']]
|
||||
if club:
|
||||
return render_template('welcome.html', club=club[0], competitions=competitions, now=now)
|
||||
flash("Sorry, that email wasn't found")
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/book/<competition>/<club>')
|
||||
def book(competition,club):
|
||||
foundClub = [c for c in clubs if c['name'] == club][0]
|
||||
foundCompetition = [c for c in competitions if c['name'] == competition][0]
|
||||
if foundClub and foundCompetition:
|
||||
return render_template('booking.html',club=foundClub,competition=foundCompetition)
|
||||
if foundCompetition['date'] > now:
|
||||
return render_template('booking.html',club=foundClub,competition=foundCompetition)
|
||||
else:
|
||||
flash("You cannot book for a past competition")
|
||||
return render_template('welcome.html', club=foundClub,
|
||||
competitions=competitions, now=now)
|
||||
else:
|
||||
flash("Something went wrong-please try again")
|
||||
return render_template('welcome.html', club=club, competitions=competitions)
|
||||
return render_template('welcome.html', club=club, competitions=competitions, now=now)
|
||||
|
||||
|
||||
@app.route('/purchasePlaces',methods=['POST'])
|
||||
@ -46,14 +56,35 @@ def purchasePlaces():
|
||||
competition = [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'])
|
||||
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
|
||||
flash('Great-booking complete!')
|
||||
return render_template('welcome.html', club=club, competitions=competitions)
|
||||
if competition['name'] in session:
|
||||
places = {competition['name']: session[competition['name']] + placesRequired}
|
||||
else:
|
||||
places = {competition['name']: placesRequired}
|
||||
points = int(club['points'])
|
||||
if placesRequired <= 12:
|
||||
if places[competition['name']] <= 12:
|
||||
if placesRequired <= points:
|
||||
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
|
||||
if not competition['name'] in session:
|
||||
session[competition['name']] = placesRequired
|
||||
flash(f"Great ! {placesRequired} places booked for {competition['name']}")
|
||||
# flash('Great-booking complete!')
|
||||
|
||||
else:
|
||||
flash("You don't have enough points")
|
||||
else:
|
||||
flash(f"You already booked 12 places for {competition['name']}")
|
||||
else:
|
||||
flash("You can't book more than 12 places")
|
||||
return render_template('welcome.html', club=club,
|
||||
competitions=competitions, now=now)
|
||||
|
||||
# TODO: Add route for points display
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
return redirect(url_for('index'))
|
||||
return redirect(url_for('index'))
|
||||
|
||||
if (__name__ == "__main__"):
|
||||
app.run(debug=True)
|
||||
|
@ -6,6 +6,16 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to the GUDLFT Registration Portal!</h1>
|
||||
{% with messages = get_flashed_messages()%}
|
||||
{% if messages %}
|
||||
<ul>
|
||||
{% for message in messages %}
|
||||
<li>{{message}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif%}
|
||||
{% endwith %}
|
||||
|
||||
Please enter your secretary email to continue:
|
||||
<form action="showSummary" method="post">
|
||||
<label for="email">Email:</label>
|
||||
@ -13,4 +23,4 @@
|
||||
<button type="submit">Enter</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -5,17 +5,17 @@
|
||||
<title>Summary | GUDLFT Registration</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
|
||||
<h2>Welcome, {{club['email']}}</h2><a href="{{url_for('logout')}}">Logout</a>
|
||||
|
||||
{% with messages = get_flashed_messages()%}
|
||||
{% if messages %}
|
||||
<ul>
|
||||
{% for message in messages %}
|
||||
{% for message in messages %}
|
||||
<li>{{message}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</ul>
|
||||
{% endif%}
|
||||
Points available: {{club['points']}}
|
||||
<b id="points">Points available: </b><span>{{club['points']}}</span>
|
||||
<h3>Competitions:</h3>
|
||||
<ul>
|
||||
{% for comp in competitions%}
|
||||
@ -23,7 +23,7 @@
|
||||
{{comp['name']}}<br />
|
||||
Date: {{comp['date']}}</br>
|
||||
Number of Places: {{comp['numberOfPlaces']}}
|
||||
{%if comp['numberOfPlaces']|int >0%}
|
||||
{%if comp['numberOfPlaces']|int >0 and comp['date'] > now%}
|
||||
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
|
||||
{%endif%}
|
||||
</li>
|
||||
@ -33,4 +33,4 @@
|
||||
{%endwith%}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
31
tests/conftest.py
Normal file
31
tests/conftest.py
Normal file
@ -0,0 +1,31 @@
|
||||
import pytest
|
||||
from server import app
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
EMAIL1 = "admin@irontemple.com"
|
||||
EMAIL2 = "john@simplylift.co"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def club1():
|
||||
data = {"competition": "Spring Festival", "club": "Iron Temple"}
|
||||
return data
|
||||
|
||||
@pytest.fixture
|
||||
def club2():
|
||||
data = {"competition": "Fall Classic", "club": "Iron Temple"}
|
||||
return data
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with app.test_client() as client:
|
||||
yield client
|
||||
|
||||
@pytest.fixture
|
||||
def connect(client):
|
||||
response = client.post('/showSummary', data={"email": EMAIL1})
|
||||
soup = BeautifulSoup(response.data, 'html.parser')
|
||||
return soup
|
||||
|
||||
|
27
tests/test_connection.py
Normal file
27
tests/test_connection.py
Normal file
@ -0,0 +1,27 @@
|
||||
from flask import session
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def test_should_status_code_ok(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_display_sorry_with_unknown_email(client):
|
||||
email = "test@test.com"
|
||||
response = client.post('/showSummary', data={"email": email})
|
||||
print(session)
|
||||
assert "_flashes" in session
|
||||
assert session["_flashes"] == [("message", "Sorry, that email wasn't found")]
|
||||
|
||||
|
||||
def test_shoul_display_page_on_known_email(client):
|
||||
email = "admin@irontemple.com"
|
||||
response = client.post('/showSummary', data={"email": email})
|
||||
print(session)
|
||||
soup = BeautifulSoup(response.data, 'html.parser')
|
||||
assert soup.h2.text == "Welcome, "+email
|
||||
|
||||
|
||||
|
||||
|
49
tests/test_purchase.py
Normal file
49
tests/test_purchase.py
Normal file
@ -0,0 +1,49 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import session
|
||||
|
||||
|
||||
class TestPoints:
|
||||
|
||||
def test_should_nok_when_too_much_points(self, client, connect, club1):
|
||||
points = int(connect.span.text)
|
||||
club1.update({"places": points+1})
|
||||
response = client.post('/purchasePlaces', data=club1)
|
||||
soup = BeautifulSoup(response.data, "html.parser")
|
||||
assert "You don't have enough points" == soup.li.text
|
||||
|
||||
def test_should_ok_when_enough_points(self, client, connect, club1):
|
||||
points = int(connect.span.text)
|
||||
club1.update({"places": points-1})
|
||||
response = client.post('/purchasePlaces', data=club1)
|
||||
soup = BeautifulSoup(response.data, "html.parser")
|
||||
# assert "Great-booking complete!" == soup.li.text
|
||||
assert f"Great ! "+str(points-1)+" places booked for "+club1['competition'] == soup.li.text
|
||||
|
||||
|
||||
class TestPlaces:
|
||||
|
||||
def test_should_refuse_more_12_once(self, client, club1):
|
||||
club1.update({"places": 13})
|
||||
response = client.post('/purchasePlaces', data=club1)
|
||||
soup = BeautifulSoup(response.data, "html.parser")
|
||||
assert "You can't book more than 12 places" == soup.li.text
|
||||
|
||||
|
||||
def test_should_refuse_more_12_total(self, client, club1):
|
||||
club1.update({"places": 2})
|
||||
response = client.post('/purchasePlaces', data=club1)
|
||||
soup = BeautifulSoup(response.data, "html.parser")
|
||||
assert "Great ! 2 places booked for "+club1['competition'] == soup.li.text
|
||||
club1.update({"places": 12})
|
||||
response = client.post('/purchasePlaces', data=club1)
|
||||
soup = BeautifulSoup(response.data, "html.parser")
|
||||
assert "You already booked 12 places for "+club1['competition'] == soup.li.text
|
||||
|
||||
|
||||
class TestDate:
|
||||
|
||||
def test_should_not_display_book_link_for_past_competitions(self, connect):
|
||||
li = connect.find_all("li")
|
||||
assert not li[0].a
|
||||
assert li[1].a
|
||||
|
Loading…
x
Reference in New Issue
Block a user