Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bin
include
lib
.Python
tests/
.envrc
__pycache__
__pycache__
venv/
.coverage
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning
47 changes: 41 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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/<competition>/<club>')
Expand Down
13 changes: 13 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GUDLFT Registration</title>
<style>
.error-message {
color: red;
}
</style>
</head>
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
Expand All @@ -12,5 +17,13 @@ <h1>Welcome to the GUDLFT Registration Portal!</h1>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>

{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<p class="error-message">{{ message }}</p>
{% endfor %}
{% endif %}
{% endwith %}
</body>
</html>
Empty file added tests/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions tests/test_login.py
Original file line number Diff line number Diff line change
@@ -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': '[email protected]'}, 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': '[email protected]', 'points': '10'}]):
response = client.post('/showSummary', data={'email': '[email protected]'})

# 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'] == '[email protected]'