Skip to content

Error/ handle unknown email error by displaying flash message #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ lib
.Python
tests/
.envrc
__pycache__
__pycache__
pyvenv.cfg
.virtualenv
.venv
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
click==7.1.2
coverage==7.6.4
exceptiongroup==1.2.2
Flask==1.1.2
iniconfig==2.0.0
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
packaging==24.1
pluggy==1.5.0
pytest==8.3.3
pytest-cov==6.0.0
tomli==2.0.2
Werkzeug==1.0.1
30 changes: 21 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import json
from flask import Flask,render_template,request,redirect,flash,url_for
from flask import Flask, render_template, request, redirect, flash, url_for


def loadClubs():
with open('clubs.json') as c:
listOfClubs = json.load(c)['clubs']
return listOfClubs
listOfClubs = json.load(c)['clubs']
return listOfClubs


def loadCompetitions():
with open('competitions.json') as comps:
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions


app = Flask(__name__)
Expand All @@ -20,14 +20,26 @@ def loadCompetitions():
competitions = loadCompetitions()
clubs = loadClubs()


@app.route('/')
def index():
return render_template('index.html')

@app.route('/showSummary',methods=['POST'])

@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)
try:
club = [
club for club in clubs
if club['email'] == request.form['email']
][0]
return render_template(
'welcome.html', club=club, competitions=competitions
)

except IndexError:
flash("Sorry, that email wasn't found.")
return redirect(url_for('index'))


@app.route('/book/<competition>/<club>')
Expand Down Expand Up @@ -56,4 +68,4 @@ def purchasePlaces():

@app.route('/logout')
def logout():
return redirect(url_for('index'))
return redirect(url_for('index'))
13 changes: 11 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
Please enter your secretary email to continue:
<form action="showSummary" method="post">
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<form action="{{ url_for('showSummary') }}" method="post">
<label for="email">Email:</label>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
</body>
</html>
</html>
34 changes: 34 additions & 0 deletions tests/unit/test_show_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
import os
import pytest
sys.path.insert(
0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '../../')
)
)

from server import app # noqa


@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as client:
yield client


def test_show_summary_email_not_found(client):
response = client.post(
'/showSummary',
data={'email': '[email protected]'},
follow_redirects=False
)

assert response.status_code == 302

with client.session_transaction() as session:
flashed_messages = session['_flashes']
assert any(
"Sorry, that email wasn't found." in message
for message in flashed_messages
)