From 32569eff4a867b20f232b16c9782a1a6b1a5dda1 Mon Sep 17 00:00:00 2001 From: devogs Date: Mon, 8 Sep 2025 11:40:42 +0200 Subject: [PATCH 1/4] Install dependencies and setup requirements and venv --- .gitignore | 5 +++-- pytest.ini | 3 +++ requirements.txt | 47 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 pytest.ini diff --git a/.gitignore b/.gitignore index 2cba99d87..0dcd0c11b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ bin include lib .Python -tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +venv/ +.coverage \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..b0e5a945f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +filterwarnings = + ignore::DeprecationWarning \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 139affa05..994cd7ba6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,41 @@ -click==7.1.2 -Flask==1.1.2 -itsdangerous==1.1.0 -Jinja2==2.11.2 -MarkupSafe==1.1.1 -Werkzeug==1.0.1 +bidict==0.23.1 +blinker==1.9.0 +Brotli==1.1.0 +certifi==2025.8.3 +charset-normalizer==3.4.3 +click==8.2.1 +ConfigArgParse==1.7.1 +coverage==7.10.6 +Flask==3.1.2 +flask-cors==6.0.1 +Flask-Login==0.6.3 +gevent==25.5.1 +geventhttpclient==2.3.4 +greenlet==3.2.4 +h11==0.16.0 +idna==3.10 +iniconfig==2.1.0 +itsdangerous==2.2.0 +Jinja2==3.1.6 +locust==2.40.0 +locust-cloud==1.26.3 +MarkupSafe==3.0.2 +msgpack==1.1.1 +packaging==25.0 +platformdirs==4.4.0 +pluggy==1.6.0 +psutil==7.0.0 +Pygments==2.19.2 +pytest==8.4.1 +python-engineio==4.12.2 +python-socketio==5.13.0 +pyzmq==27.0.2 +requests==2.32.5 +setuptools==80.9.0 +simple-websocket==1.1.0 +urllib3==2.5.0 +websocket-client==1.8.0 +Werkzeug==3.1.3 +wsproto==1.2.0 +zope.event==5.1.1 +zope.interface==7.2 From d4e2057fe947b628faf29e24c37c58342416468d Mon Sep 17 00:00:00 2001 From: devogs Date: Mon, 8 Sep 2025 12:13:07 +0200 Subject: [PATCH 2/4] Create test to check missing email resiliency and flash message is present --- tests/test_login.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_login.py diff --git a/tests/test_login.py b/tests/test_login.py new file mode 100644 index 000000000..e5b620518 --- /dev/null +++ b/tests/test_login.py @@ -0,0 +1,40 @@ +import pytest +from server import app, clubs, competitions +from unittest.mock import patch, MagicMock + + +@pytest.fixture +def client(): + """Configures the Flask test client and yields it for testing.""" + app.config['TESTING'] = True + with app.test_client() as client: + yield client + +def test_unknown_email_flashes_message(client): + """Test that an unknown email results in a flash message being stored.""" + # Mock the 'clubs' data so that the email is not found + with patch('server.clubs', []): + response = client.post('/showSummary', data={'email': 'unknown@test.com'}, follow_redirects=False) + + # Check the flash messages stored in the session + with client.session_transaction() as sess: + flashed_messages = dict(sess.get('_flashes', [])) + + assert response.status_code == 302 + assert response.location == '/' + assert "Sorry, that email was not found." in flashed_messages.values() + +def test_existing_email_login_is_successful(client): + """Test that a user with an existing email can log in and view the welcome page.""" + # Mock the 'clubs' data to include a known user + with patch('server.clubs', [{'name': 'Test Club', 'email': 'test@test.com', 'points': '10'}]): + response = client.post('/showSummary', data={'email': 'test@test.com'}) + + # Assertions + assert response.status_code == 200 + assert b'Welcome' in response.data + + # Check that the email was stored in the session + with client.session_transaction() as sess: + assert 'club_email' in sess + assert sess['club_email'] == 'test@test.com' \ No newline at end of file From 72c2c6e466d8d31e1085810fa27d1c6b271a0fbe Mon Sep 17 00:00:00 2001 From: devogs Date: Mon, 8 Sep 2025 12:15:26 +0200 Subject: [PATCH 3/4] Add an __init__.py file to treat the parent directory as a package --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb From 946b053cc76a44f418f9035b5227e102ae32f448 Mon Sep 17 00:00:00 2001 From: devogs Date: Mon, 8 Sep 2025 12:24:59 +0200 Subject: [PATCH 4/4] Fix: email missing resiliency and flash message in index --- server.py | 16 +++++++++++++--- templates/index.html | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 4084baeac..5d303539d 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,5 @@ import json -from flask import Flask,render_template,request,redirect,flash,url_for +from flask import Flask,render_template,request,redirect,flash,url_for,session def loadClubs(): @@ -24,10 +24,20 @@ def loadCompetitions(): def index(): return render_template('index.html') + @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) + user_email = request.form['email'] + found_clubs = [club for club in clubs if club['email'] == user_email] + + if found_clubs: + club = found_clubs[0] + session['club_email'] = club['email'] + return render_template('welcome.html',club=club,competitions=competitions) + else: + flash("Sorry, that email was not found.") + session.pop('club_email', None) + return redirect(url_for('index')) @app.route('/book//') diff --git a/templates/index.html b/templates/index.html index 926526b7d..cfa154e7b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,6 +3,11 @@ GUDLFT Registration +

Welcome to the GUDLFT Registration Portal!

@@ -12,5 +17,13 @@

Welcome to the GUDLFT Registration Portal!

+ + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +

{{ message }}

+ {% endfor %} + {% endif %} + {% endwith %} \ No newline at end of file