Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ bin
include
lib
.Python
tests/
.envrc
__pycache__
__pycache__
.venv
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 11 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<competition>/<club>')
Expand Down Expand Up @@ -56,4 +61,7 @@ def purchasePlaces():

@app.route('/logout')
def logout():
return redirect(url_for('index'))
return redirect(url_for('index'))

if __name__ == '__main__':
app.run(debug=True)
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
Please enter your secretary email to continue:
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class="flashes" style="color: red;">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<form action="showSummary" method="post">
<label for="email">Email:</label>
<input type="email" name="email" id=""/>
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 29 additions & 0 deletions tests/unit/test_show_summary.py
Original file line number Diff line number Diff line change
@@ -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': '[email protected]'})
assert response.status_code == 200
assert b'Welcome' in response.data
assert b'[email protected]' in response.data


def test_show_summary_with_unknown_email(client):
response = client.post('/showSummary', data={'email': '[email protected]'})
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