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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6af571a93 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "python.testing.framework": "pytest", + "python.testing.pytestEnabled": true, + "python.testing.autoTestDiscoverOnSaveEnabled": true, + "python.testing.pytestPath": "pytest", + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false +} \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..a5ecdcd44 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//') @@ -56,4 +61,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/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..a850a4c72 --- /dev/null +++ b/tests/unit/conftest.py @@ -0,0 +1,7 @@ +import os +import sys + +# Ensure project root is on sys.path so tests can import server.py +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) diff --git a/tests/unit/test_show_summary.py b/tests/unit/test_show_summary.py new file mode 100644 index 000000000..81dd1df91 --- /dev/null +++ b/tests/unit/test_show_summary.py @@ -0,0 +1,29 @@ +import pytest + +from server import app + + +@pytest.fixture +def client(): + app.config['TESTING'] = True + with app.test_client() as client: + yield client + + +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 + assert b'john@simplylift.co' 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