diff --git a/.gitignore b/.gitignore index 2cba99d87..3505a1411 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ bin include lib .Python -tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +.git +.env +.idea diff --git a/server.py b/server.py index 4084baeac..95b8359e9 100644 --- a/server.py +++ b/server.py @@ -17,6 +17,10 @@ def loadCompetitions(): app = Flask(__name__) app.secret_key = 'something_special' + +if __name__ == '__main__': + app.run(debug=True) + competitions = loadCompetitions() clubs = loadClubs() @@ -24,10 +28,18 @@ 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'] + 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//') diff --git a/templates/index.html b/templates/index.html index 926526b7d..4e97d083c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,5 +12,15 @@

Welcome to the GUDLFT Registration Portal!

+ + {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} - \ No newline at end of file + diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration/test_email_integration.py b/tests/integration/test_email_integration.py new file mode 100644 index 000000000..ffa57a1c7 --- /dev/null +++ b/tests/integration/test_email_integration.py @@ -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': 'fabien@test.com'}, + 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': 'admin@irontemple.com'}, + follow_redirects=True + ) + assert response.status_code == 200 + + page = response.data.decode('utf-8') + assert "Welcome, admin@irontemple.com" in page + assert "Désolé" not in page + + print("[SUCCÈS] Email valide → connexion OK") diff --git a/tests/unit/test_email_logic.py b/tests/unit/test_email_logic.py new file mode 100644 index 000000000..0e83d32a1 --- /dev/null +++ b/tests/unit/test_email_logic.py @@ -0,0 +1,30 @@ +import pytest + +CLUBS = [ + {"name": "Iron Temple", "email": "admin@irontemple.com", "points": "4"}, + {"name": "Simply Lift", "email": "john@simplylift.co", "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("fabien@faux.com") + assert result is None + print("[ERREUR] Email invalide") + + +def test_email_trouve(): + result = rechercher_email("admin@irontemple.com") + assert result is not None + assert result["name"] == "Iron Temple" + print("[SUCCÈS] Email valide") + + + +