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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ bin
include
lib
.Python
tests/
.envrc
__pycache__
__pycache__
.git
.env
.idea
18 changes: 15 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,29 @@ def loadCompetitions():
app = Flask(__name__)
app.secret_key = 'something_special'


if __name__ == '__main__':
app.run(debug=True)

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)
email = request.form['email']
club_trouve = None
for club in clubs:
if club['email'] == email:
club_trouve = club
break
if club_trouve is None:
flash("Sorry, the email is not registered in the database")
return redirect(url_for('index'))
return render_template('welcome.html', club=club_trouve, competitions=competitions)


@app.route('/book/<competition>/<club>')
Expand Down
12 changes: 11 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@ <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 %}
<ul style="color: red; font-weight: bold; background: #ffeeee; padding: 10px; border: 2px solid red; list-style: none;">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
</body>
</html>
</html>
Empty file added tests/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions tests/integration/test_email_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from server import app
import pytest


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


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

page = response.data.decode('utf-8')

assert "Sorry" in page
assert "the email is not registered in the database" in page

print("[ERREUR] Email invalide → message bien affiché")


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

page = response.data.decode('utf-8')
assert "Welcome, [email protected]" in page
assert "Désolé" not in page

print("[SUCCÈS] Email valide → connexion OK")
30 changes: 30 additions & 0 deletions tests/unit/test_email_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest

CLUBS = [
{"name": "Iron Temple", "email": "[email protected]", "points": "4"},
{"name": "Simply Lift", "email": "[email protected]", "points": "13"}
]


def rechercher_email(email):
for club in CLUBS:
if club['email'] == email:
return club
return None


def test_email_pas_trouve():
result = rechercher_email("[email protected]")
assert result is None
print("[ERREUR] Email invalide")


def test_email_trouve():
result = rechercher_email("[email protected]")
assert result is not None
assert result["name"] == "Iron Temple"
print("[SUCCÈS] Email valide")