Skip to content

BUG : Entering a unknown email crashes the app #291

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
15 changes: 12 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ def loadCompetitions():
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)
email = request.form['email']
matching_clubs = [club for club in clubs if club['email'] == email]

if len(matching_clubs) == 0:
flash("Désolé, cette adresse e-mail est introuvable.")
return redirect(url_for('index'))

club = matching_clubs[0]
return render_template('welcome.html', club=club, competitions=competitions)



@app.route('/book/<competition>/<club>')
Expand Down
11 changes: 11 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
</head>
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>

{% with messages = get_flashed_messages()%}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{% endif%}
{% endwith %}

Please enter your secretary email to continue:
<form action="showSummary" method="post">
<label for="email">Email:</label>
Expand Down
30 changes: 30 additions & 0 deletions test/tests_unitaires/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from server import app, clubs


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

def test_showSummary_email_found(client):
test_email = "[email protected]"
test_club = {'email': test_email, 'name': 'Test Club'}
clubs.append(test_club)

response = client.post('/showSummary', data={'email': test_email})
assert response.status_code == 200

html = response.data.decode('utf-8')
assert 'Test%20Club' in html # ou '/book/Test%20Club'

clubs.remove(test_club)

def test_showSummary_email_not_found(client):
response = client.post('/showSummary', data={'email': '[email protected]'}, follow_redirects=True)
assert response.status_code == 200

html = response.data.decode('utf-8')
assert "Désolé, cette adresse e-mail est introuvable." in html