diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 04a508e6f..000000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 2cba99d87..950060a15 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ bin include lib .Python -tests/ .envrc __pycache__ \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..de19c9f0b --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +testpaths = tests \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 139affa05..8f10818fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..a58f8b437 100644 --- a/server.py +++ b/server.py @@ -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//') @@ -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) diff --git a/templates/index.html b/templates/index.html index 926526b7d..ecfe61c61 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,6 +5,15 @@ GUDLFT Registration + {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %}

Welcome to the GUDLFT Registration Portal!

Please enter your secretary email to continue:
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..570ed6d5b --- /dev/null +++ b/tests/conftest.py @@ -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 + diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration/test_login.py b/tests/integration/test_login.py new file mode 100644 index 000000000..c7cc014af --- /dev/null +++ b/tests/integration/test_login.py @@ -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 \ No newline at end of file diff --git a/tests/integration/test_purchase.py b/tests/integration/test_purchase.py new file mode 100644 index 000000000..39748596c --- /dev/null +++ b/tests/integration/test_purchase.py @@ -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 \ No newline at end of file diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb