diff --git a/.flaskenv b/.flaskenv new file mode 100644 index 000000000..10950ca46 --- /dev/null +++ b/.flaskenv @@ -0,0 +1,2 @@ +FLASK_APP=server +FLASK_ENV=development \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2cba99d87..f577272a5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ bin include lib .Python -tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +.venv \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 139affa05..7a3b0bf04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,13 @@ click==7.1.2 +colorama==0.4.6 Flask==1.1.2 +iniconfig==2.3.0 itsdangerous==1.1.0 Jinja2==2.11.2 MarkupSafe==1.1.1 +packaging==25.0 +pluggy==1.6.0 +Pygments==2.19.2 +pytest==8.4.2 +python-dotenv==1.1.1 Werkzeug==1.0.1 diff --git a/server.py b/server.py index 4084baeac..43c1340ce 100644 --- a/server.py +++ b/server.py @@ -26,8 +26,13 @@ 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) + email = request.form.get('email', '') + email = email.strip() + club = next((c for c in clubs if c.get('email', '').strip() == email), None) + if not email or not club: + flash("Sorry, that email was not found, please try again.") + return render_template('index.html') + return render_template('welcome.html', club=club, competitions=competitions) @app.route('/book//') diff --git a/templates/index.html b/templates/index.html index 926526b7d..ae4e91eb1 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 %} + + {% endif %} + {% endwith %}
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py new file mode 100644 index 000000000..7153001ce --- /dev/null +++ b/tests/unit/conftest.py @@ -0,0 +1,23 @@ +import os +import sys +import pytest + + +"""Pytest configuration file to set up the testing environment. +This file adds the project root directory to sys.path to ensure that +""" + +ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) +if ROOT_DIR not in sys.path: + sys.path.insert(0, ROOT_DIR) + +from server import app + +@pytest.fixture +def client(): + """Flask test client fixture. + Provides a test client for the Flask application defined in server.py. + """ + app.config['TESTING'] = True + with app.test_client() as client: + yield client \ No newline at end of file diff --git a/tests/unit/test_check_email_show_summary.py b/tests/unit/test_check_email_show_summary.py new file mode 100644 index 000000000..4e6428c9b --- /dev/null +++ b/tests/unit/test_check_email_show_summary.py @@ -0,0 +1,27 @@ +import pytest + + +"""Unit tests for the /showSummary route in server.py. +test1 : Valid email should return 200 and welcome message +test2 : Unknown email should return 200 and error message +test3 : Invalid email (empty or whitespace) should return 200 and error message + +""" + + +def test_show_summary_with_valid_email(client): + response = client.post('/showSummary', data={'email': 'john@simplylift.co'}) + 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@example.com'}) + assert response.status_code == 200 + assert b"Sorry, that email was not found" in response.data + + +def test_show_summary_with_invalid_email(client): + response = client.post('/showSummary', data={'email': ' '}) + assert response.status_code == 200 + assert b"Sorry, that email was not found" in response.data \ No newline at end of file