From 201c47df2b9db3a850313b97e19e073d0ac4ed5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Amorin?= Date: Fri, 24 Apr 2026 11:30:37 +0200 Subject: [PATCH 1/5] fix: handle unknown email in showSummary --- .env | 0 .gitignore | 4 +++- conftest.py | 10 ++++++++++ server.py | 13 ++++++++++--- templates/index.html | 9 +++++++++ test/test_server.py | 17 +++++++++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 .env create mode 100644 conftest.py create mode 100644 test/test_server.py diff --git a/.env b/.env new file mode 100644 index 000000000..e69de29bb diff --git a/.gitignore b/.gitignore index 2cba99d87..97c0d2d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ lib .Python tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +env +.vscode \ No newline at end of file diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..3e547e262 --- /dev/null +++ b/conftest.py @@ -0,0 +1,10 @@ +import pytest +from server import app + + +@pytest.fixture +def client(): + app.config["TESTING"] = True + + with app.test_client() as client: + yield client \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..38f5aae79 100644 --- a/server.py +++ b/server.py @@ -13,7 +13,7 @@ def loadCompetitions(): listOfCompetitions = json.load(comps)['competitions'] return listOfCompetitions - +a = 1 app = Flask(__name__) app.secret_key = 'something_special' @@ -26,8 +26,15 @@ 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 not club: + flash("Sorry, that email was not found") + return redirect(url_for("index")) + + return render_template('welcome.html', + club=club[0], + competitions=competitions) @app.route('/book//') diff --git a/templates/index.html b/templates/index.html index 926526b7d..b7ae99c98 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,15 @@

Welcome to the GUDLFT Registration Portal!

Please enter your secretary email to continue: + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +

{{ message }}

+ {% endfor %} + {% endif %} + {% endwith %} +
diff --git a/test/test_server.py b/test/test_server.py new file mode 100644 index 000000000..9fa39a3d9 --- /dev/null +++ b/test/test_server.py @@ -0,0 +1,17 @@ + + +def test_show_summary_with_valid_email(client): + response = client.post("/showSummary", data={ + "email": "admin@irontemple.com" + }) + + assert response.status_code == 200 + assert b"Welcome" in response.data + +def test_show_summary_with_unknown_email(client): + response = client.post("/showSummary", data={ + "email": "unknown@test.com" + }, follow_redirects=True) + + assert response.status_code == 200 + assert b"Sorry, that email was not found" in response.data \ No newline at end of file From 2c215e77913bb63d8b97ddddec7621d8753353fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Amorin?= Date: Thu, 30 Apr 2026 10:10:24 +0200 Subject: [PATCH 2/5] ignore local environment files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2cba99d87..07ede88a6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ lib .Python tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +.env +.vscode/ +env/ \ No newline at end of file From 6c9f55c90ac99947891dc0b4565439fcff33ccae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Amorin?= Date: Wed, 29 Apr 2026 11:34:31 +0200 Subject: [PATCH 3/5] fix: prevent clubs from redeeming more points than available --- pytest.ini | 3 +++ server.py | 12 +++++++++--- templates/welcome.html | 5 ++++- test/test_server.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 pytest.ini create mode 100644 test/test_server.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..b0e5a945f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +filterwarnings = + ignore::DeprecationWarning \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..206e53935 100644 --- a/server.py +++ b/server.py @@ -46,9 +46,15 @@ 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) + + point_club = int(club['points']) + if point_club < placesRequired: + flash('You are not authorized to book this number of places!') + return render_template('welcome.html', club=club, competitions=competitions) + else: + flash('Great-booking complete!') + competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired + return render_template('welcome.html', club=club, competitions=competitions) # TODO: Add route for points display diff --git a/templates/welcome.html b/templates/welcome.html index ff6b261a2..d2ea76a30 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -5,7 +5,8 @@ Summary | GUDLFT Registration -

Welcome, {{club['email']}}

Logout +

Welcome, {{club['email']}} +

Logout {% with messages = get_flashed_messages()%} {% if messages %} @@ -15,7 +16,9 @@

Welcome, {{club['email']}}

Logout {% endfor %} {% endif%} + Points available: {{club['points']}} +

Competitions:

    {% for comp in competitions%} diff --git a/test/test_server.py b/test/test_server.py new file mode 100644 index 000000000..df0054832 --- /dev/null +++ b/test/test_server.py @@ -0,0 +1,42 @@ +def test_show_summary_with_valid_email(client): + response = client.post("/showSummary", data={ + "email": "admin@irontemple.com" + }) + + assert response.status_code == 200 + assert b"Welcome" in response.data + +def test_show_summary_with_unknown_email(client): + response = client.post("/showSummary", data={ + "email": "unknown@test.com" + }, follow_redirects=True) + + assert response.status_code == 200 + assert b"Sorry, that email was not found" in response.data + + + + +def test_purchase_places_with_valid_number_of_places(client): + response = client.post("/purchasePlaces", data={ + "competition": "Spring Festival", + "club": "Iron Temple", + "places": "2" + }, follow_redirects=True) + + assert response.status_code == 200 + assert b"Great-booking complete!" in response.data + +def test_purchase_places_with_too_many_places(client): + response = client.post("/purchasePlaces", data={ + "competition": "Spring Festival", + "club": "Iron Temple", + "places": "5", + }) + + assert response.status_code == 200 + assert b"You are not authorized to book this number of places" in response.data + + + + From 9d61a1c370b61f9b8ed0ff447b08d47af4959514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Amorin?= Date: Thu, 30 Apr 2026 11:03:47 +0200 Subject: [PATCH 4/5] test: add pytest fixture --- conftest.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 conftest.py diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..af2edad74 --- /dev/null +++ b/conftest.py @@ -0,0 +1,12 @@ +import pytest +from server import app + + +@pytest.fixture +def client(): + # active le mode test de Flask + app.config["TESTING"] = True + # crée un faux navigateur + with app.test_client() as client: + # donne ce navigateur aux tests + yield client \ No newline at end of file From 25e6e689d6bf24d212ef0dbc99895a420394a7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Amorin?= Date: Thu, 30 Apr 2026 11:17:16 +0200 Subject: [PATCH 5/5] chore: remove .env from repository --- .env | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index e69de29bb..000000000