From 93f730963ff32f4816489e95e96fcf5465fa4b07 Mon Sep 17 00:00:00 2001 From: Jean-Chrisrophe Ozanne Date: Wed, 22 Jan 2025 11:40:51 +0100 Subject: [PATCH 1/3] fix email validation in ShowSummary route --- server.py | 11 ++++++++-- tests/__init__.py | 0 tests/unit_tests/__init__.py | 0 tests/unit_tests/conftest.py | 9 ++++++++ .../unit_tests/test_valid_or_invalid_mail.py | 22 +++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/unit_tests/__init__.py create mode 100644 tests/unit_tests/conftest.py create mode 100644 tests/unit_tests/test_valid_or_invalid_mail.py diff --git a/server.py b/server.py index 4084baeac..6438dbcb4 100644 --- a/server.py +++ b/server.py @@ -26,7 +26,11 @@ def index(): @app.route('/showSummary',methods=['POST']) def showSummary(): - club = [club for club in clubs if club['email'] == request.form['email']][0] + try: + club = [club for club in clubs if club['email'] == request.form['email']][0] + except IndexError: + flash("email not found or invalid please try again") + return redirect(url_for('index')) return render_template('welcome.html',club=club,competitions=competitions) @@ -56,4 +60,7 @@ def purchasePlaces(): @app.route('/logout') def logout(): - return redirect(url_for('index')) \ No newline at end of file + return redirect(url_for('index')) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit_tests/__init__.py b/tests/unit_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py new file mode 100644 index 000000000..ad2e53992 --- /dev/null +++ b/tests/unit_tests/conftest.py @@ -0,0 +1,9 @@ +import pytest + +from server import app + + +@pytest.fixture +def client(): + app.config["TESTING"] = True + return app.test_client() \ No newline at end of file diff --git a/tests/unit_tests/test_valid_or_invalid_mail.py b/tests/unit_tests/test_valid_or_invalid_mail.py new file mode 100644 index 000000000..a78f8e5eb --- /dev/null +++ b/tests/unit_tests/test_valid_or_invalid_mail.py @@ -0,0 +1,22 @@ +import pytest + +def test_connection_with_valid_email(client): + result = client.post("/showSummary", data={"email": "john@simplylift.co"}) + assert result.status_code == 200 + assert f"john@simplylift.co" in result.data.decode() + +def test_connection_with_invalid_email_no_at(client): + result = client.post("/showSummary", data={"email": "johnsimplylift.co"}) + assert result.status_code == 302 + +def test_connection_with_invalid_email_no_dot(client): + result = client.post("/showSummary", data={"email": "john@simplyliftco"}) + assert result.status_code == 302 + +def test_connection_with_empty_email(client): + result = client.post("/showSummary", data={"email": ""}) + assert result.status_code == 302 + +def test_logout(client): + result = client.get("/logout") + assert result.status_code == 302 \ No newline at end of file From 25a125692453a24f14eb6be04b8c19fdf840a81a Mon Sep 17 00:00:00 2001 From: Jean-Chrisrophe Ozanne Date: Fri, 24 Jan 2025 11:17:47 +0100 Subject: [PATCH 2/3] test --- templates/welcome.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/welcome.html b/templates/welcome.html index ff6b261a2..f4be19a12 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -16,12 +16,12 @@

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

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

Competitions:

+

Competitions :

{% endif%} Points available: {{club['points']}} -

Competitions :

+

Competitions: