Compare commits

..

No commits in common. "bug/issue5" and "main" have entirely different histories.

10 changed files with 19 additions and 167 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -7,7 +7,7 @@
}, },
{ {
"name": "Fall Classic", "name": "Fall Classic",
"date": "2025-10-22 13:30:00", "date": "2020-10-22 13:30:00",
"numberOfPlaces": "13" "numberOfPlaces": "13"
} }
] ]

View File

@ -1,6 +1,5 @@
import json import json
from flask import Flask,render_template,request,redirect,flash,url_for,session from flask import Flask,render_template,request,redirect,flash,url_for
from datetime import datetime
def loadClubs(): def loadClubs():
@ -20,8 +19,6 @@ app.secret_key = 'something_special'
competitions = loadCompetitions() competitions = loadCompetitions()
clubs = loadClubs() clubs = loadClubs()
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
@app.route('/') @app.route('/')
def index(): def index():
@ -29,26 +26,19 @@ def index():
@app.route('/showSummary',methods=['POST']) @app.route('/showSummary',methods=['POST'])
def showSummary(): def showSummary():
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]
if club: return render_template('welcome.html',club=club,competitions=competitions)
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>') @app.route('/book/<competition>/<club>')
def book(competition,club): def book(competition,club):
foundClub = [c for c in clubs if c['name'] == club][0] foundClub = [c for c in clubs if c['name'] == club][0]
foundCompetition = [c for c in competitions if c['name'] == competition][0] foundCompetition = [c for c in competitions if c['name'] == competition][0]
if foundClub and foundCompetition: if foundClub and foundCompetition:
if foundCompetition['date'] > now:
return render_template('booking.html',club=foundClub,competition=foundCompetition) 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: else:
flash("Something went wrong-please try again") 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']) @app.route('/purchasePlaces',methods=['POST'])
@ -56,28 +46,10 @@ def purchasePlaces():
competition = [c for c in competitions if c['name'] == request.form['competition']][0] 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] club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places']) placesRequired = int(request.form['places'])
if competition['name'] in session: competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
places = {competition['name']: session[competition['name']] + placesRequired} flash('Great-booking complete!')
else: return render_template('welcome.html', club=club, competitions=competitions)
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 # TODO: Add route for points display
@ -85,6 +57,3 @@ def purchasePlaces():
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
return redirect(url_for('index')) return redirect(url_for('index'))
if (__name__ == "__main__"):
app.run(debug=True)

View File

@ -6,16 +6,6 @@
</head> </head>
<body> <body>
<h1>Welcome to the GUDLFT Registration Portal!</h1> <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: Please enter your secretary email to continue:
<form action="showSummary" method="post"> <form action="showSummary" method="post">
<label for="email">Email:</label> <label for="email">Email:</label>

View File

@ -5,7 +5,7 @@
<title>Summary | GUDLFT Registration</title> <title>Summary | GUDLFT Registration</title>
</head> </head>
<body> <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()%} {% with messages = get_flashed_messages()%}
{% if messages %} {% if messages %}
@ -15,7 +15,7 @@
{% endfor %} {% endfor %}
</ul> </ul>
{% endif%} {% endif%}
<b id="points">Points available: </b><span>{{club['points']}}</span> Points available: {{club['points']}}
<h3>Competitions:</h3> <h3>Competitions:</h3>
<ul> <ul>
{% for comp in competitions%} {% for comp in competitions%}
@ -23,7 +23,7 @@
{{comp['name']}}<br /> {{comp['name']}}<br />
Date: {{comp['date']}}</br> Date: {{comp['date']}}</br>
Number of Places: {{comp['numberOfPlaces']}} 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> <a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
{%endif%} {%endif%}
</li> </li>

View File

View File

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

View File

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

View File

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