7 Commits

Author SHA1 Message Date
79a6b00401 removed print 2025-07-07 10:27:54 +02:00
0370de60e0 added ok and nok on points 2025-07-03 11:41:17 +02:00
813b7849fe test Ok on soup 2025-07-02 17:27:06 +02:00
9705789809 works better with init 2025-07-02 15:07:28 +02:00
b34382c46c first try to get session cookie 2025-07-02 15:06:46 +02:00
90cae5ffc9 first try with fixture for login 2025-07-02 11:36:51 +02:00
d3e9eda937 let this fix for issue6 2025-06-30 10:32:46 +02:00
10 changed files with 92 additions and 65 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -7,7 +7,7 @@
{
"name":"Iron Temple",
"email": "admin@irontemple.com",
"points":"47"
"points":"4"
},
{ "name":"She Lifts",
"email": "kate@shelifts.co.uk",

View File

@@ -1,6 +1,5 @@
import json
from flask import Flask,render_template,request,redirect,flash,url_for,session
from datetime import datetime
from flask import Flask,render_template,request,redirect,flash,url_for
def loadClubs():
@@ -20,8 +19,6 @@ app.secret_key = 'something_special'
competitions = loadCompetitions()
clubs = loadClubs()
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
@app.route('/')
def index():
@@ -31,8 +28,8 @@ def index():
def showSummary():
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("The email isn't found")
return render_template('welcome.html', club=club[0], competitions=competitions)
flash("Sorry, that email wasn't found")
return redirect(url_for('index'))
@app.route('/book/<competition>/<club>')
@@ -40,15 +37,10 @@ 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:
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)
return render_template('booking.html',club=foundClub,competition=foundCompetition)
else:
flash("Something went wrong-please try again")
return render_template('welcome.html', club=club, competitions=competitions, now=now)
return render_template('welcome.html', club=club, competitions=competitions)
@app.route('/purchasePlaces',methods=['POST'])
@@ -56,37 +48,21 @@ 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'])
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
club['points'] = int(club['points']) - placesRequired
print(club['points'])
if not competition['name'] in session:
session[competition['name']] = placesRequired
flash(f"Great ! {placesRequired} places booked for {competition['name']}")
else:
flash("You don't have enough points")
else:
flash(f"You already booked 12 places for {competition['name']}")
if placesRequired <= points:
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
if competition['numberOfPlaces'] < 0:
competition['numberOfPlaces'] = 0
flash("Great-booking complete!")
else:
flash("You can't book more than 12 places")
return render_template('welcome.html', club=club,
competitions=competitions, now=now)
flash("You don't have enough points")
return render_template('welcome.html', club=club, competitions=competitions)
# TODO: Add route for points display
@app.route('/points')
def displayPoints():
return render_template('points.html', clubs=clubs)
@app.route('/logout')
def logout():
return redirect(url_for('index'))
if (__name__ == "__main__"):
app.run(debug=True)

View File

@@ -22,6 +22,5 @@
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
<a href="{{ url_for('displayPoints') }}">Board of points</a>
</body>
</html>

View File

@@ -1,18 +0,0 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Board of clubs and points || GUDLFT</title>
</head>
<body>
<h2>Current points</h2>
<ul>
{% for club in clubs %}
<li><strong>club : </strong> {{club['name']}} </br>
<strong>Points : </strong>{{club['points']}}</br>
</br>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}"> Back </a>
</body>
</html>

View File

@@ -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 and comp['date'] > now%}
{%if comp['numberOfPlaces']|int >0%}
<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
View File

28
tests/conftest.py Normal file
View File

@@ -0,0 +1,28 @@
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

23
tests/test_connection.py Normal file
View File

@@ -0,0 +1,23 @@
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})
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})
soup = BeautifulSoup(response.data, 'html.parser')
assert soup.h2.text == "Welcome, "+email

19
tests/test_purchase.py Normal file
View File

@@ -0,0 +1,19 @@
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)
data = club1.update({"places": points-1})
response = client.post('/purchasePlaces', data=club1)
soup = BeautifulSoup(response.data, "html.parser")
assert "Great-booking complete!" == soup.li.text