Skip to content
Open
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
Binary file removed .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ bin
include
lib
.Python
tests/
.envrc
__pycache__
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
testpaths = tests
15 changes: 9 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
click==8.1.7
Flask==3.0.3
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
Werkzeug==3.0.4
pytest==8.3.3
pytest-cov==5.0.0
locust==2.31.6
9 changes: 7 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ 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)
matching_clubs = [c for c in clubs if c['email'] == request.form['email']]
if not matching_clubs:
flash("Sorry, that email was not found.")
return redirect(url_for('index'))
club = matching_clubs[0]
return render_template('welcome.html', club=club, competitions=competitions)


@app.route('/book/<competition>/<club>')
Expand All @@ -47,6 +51,7 @@ def purchasePlaces():
club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places'])
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
club['points'] = int(club['points']) - placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)

Expand Down
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
<title>GUDLFT Registration</title>
</head>
<body>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<h1>Welcome to the GUDLFT Registration Portal!</h1>
Please enter your secretary email to continue:
<form action="showSummary" method="post">
Expand Down
Empty file added tests/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

import server


@pytest.fixture
def client():
server.app.config['TESTING'] = True
with server.app.test_client() as client:
yield client

Empty file added tests/functional/__init__.py
Empty file.
Empty file added tests/integration/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions tests/integration/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def test_login_with_valid_email_shows_summary(client):
"""Happy path : un email connu doit afficher la page de résumé."""
response = client.post(
"/showSummary",
data={"email": "john@simplylift.co"},
)
assert response.status_code == 200
assert b"john@simplylift.co" in response.data


def test_login_with_unknown_email_does_not_crash(client):
"""Sad path (bug #1) : un email inconnu ne doit pas faire planter l'appli."""
response = client.post(
"/showSummary",
data={"email": "inconnu@test.com"},
follow_redirects=True,
)
assert response.status_code == 200
assert b"Sorry, that email was not found." in response.data
25 changes: 25 additions & 0 deletions tests/integration/test_purchase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import server


def test_purchase_deducts_points_from_club(client):
"""Bug #6 : les points utilises doivent etre deduits du solde du club."""
# On choisit un club et une competition connus
club = next(c for c in server.clubs if c['name'] == "Simply Lift")
competition = next(
c for c in server.competitions if c['name'] == "Spring Festival"
)

points_avant = int(club['points'])
places_reservees = 3

client.post(
"/purchasePlaces",
data={
"competition": competition['name'],
"club": club['name'],
"places": str(places_reservees),
},
)

points_apres = int(club['points'])
assert points_apres == points_avant - places_reservees
Empty file added tests/unit/__init__.py
Empty file.