From b70f80f3cbdfb7bae7250700e9b36256547146ff Mon Sep 17 00:00:00 2001 From: yann Date: Fri, 20 Jun 2025 15:12:59 +0200 Subject: [PATCH 1/8] added checking and substracting points --- server.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 4112082..0a12660 100644 --- a/server.py +++ b/server.py @@ -48,9 +48,18 @@ def purchasePlaces(): competition = [c for c in competitions if c['name'] == request.form['competition']][0] club = [c for c in clubs if c['name'] == request.form['club']][0] placesRequired = int(request.form['places']) - competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired - flash('Great-booking complete!') - return render_template('welcome.html', club=club, competitions=competitions) + points = int(club['points']) + if placesRequired <= points: + competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired + club['points'] = int(club['points']) - placesRequired + if competition['numberOfPlaces'] < 0: + competition['numberOfPlaces'] = 0 + flash('Great-booking complete!') + else: + flash("You don't have enough points") + return render_template('welcome.html', club=club, + competitions=competitions) + # TODO: Add route for points display From d3e9eda937fffd6834b3a641dfb1297dd7367c31 Mon Sep 17 00:00:00 2001 From: yann Date: Mon, 30 Jun 2025 10:32:46 +0200 Subject: [PATCH 2/8] let this fix for issue6 --- server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/server.py b/server.py index 0a12660..b0d68c3 100644 --- a/server.py +++ b/server.py @@ -51,7 +51,6 @@ def purchasePlaces(): points = int(club['points']) if placesRequired <= points: competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired - club['points'] = int(club['points']) - placesRequired if competition['numberOfPlaces'] < 0: competition['numberOfPlaces'] = 0 flash('Great-booking complete!') From 90cae5ffc98b3922e91d37b7d4cc8cef188ceec1 Mon Sep 17 00:00:00 2001 From: yann Date: Wed, 2 Jul 2025 11:36:51 +0200 Subject: [PATCH 3/8] first try with fixture for login --- tests/conftest.py | 17 +++++++++++++++++ tests/test_connection.py | 23 +++++++++++++++++++++++ tests/test_purchase.py | 5 +++++ 3 files changed, 45 insertions(+) create mode 100644 tests/conftest.py create mode 100644 tests/test_connection.py create mode 100644 tests/test_purchase.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..50e7972 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,17 @@ +import pytest +from server import app + +EMAIL1 = "admin@irontemple.com" +EMAIL2 = "john@simplylift.co" + +@pytest.fixture +def client(): + with app.test_client() as client: + yield client + + +@pytest.fixture +def connect(client): + response = client.post('/showSummary', data={"email": EMAIL}) + soup = BeautifulSoup(response.data, 'html.parser') + diff --git a/tests/test_connection.py b/tests/test_connection.py new file mode 100644 index 0000000..22b664f --- /dev/null +++ b/tests/test_connection.py @@ -0,0 +1,23 @@ +from flask import session +from bs4 import BeautifulSoup + + +def test_should_status_code_ok(client): + response = client.get('/') + assert response.status_code == 200 + + +def test_should_display_sorry_with_unknown_email(client): + email = "test@test.com" + response = client.post('/showSummary', data={"email": email}) + assert "_flashes" in session + assert session["_flashes"] == [("message", "Sorry, that email wasn't found")] + + +def test_shoul_display_page_on_known_email(client): + email = "admin@irontemple.com" + response = client.post('/showSummary', data={"email": email}) + soup = BeautifulSoup(response.data, 'html.parser') + assert soup.h2.text == "Welcome, "+email + + diff --git a/tests/test_purchase.py b/tests/test_purchase.py new file mode 100644 index 0000000..abb03e3 --- /dev/null +++ b/tests/test_purchase.py @@ -0,0 +1,5 @@ +from bs4 import BeautifulSoup + + +def test_should_not_when_try_more_points_than_available(connect): + print(response.data) From b34382c46c8f4781e0ba130786f7a3217b168a51 Mon Sep 17 00:00:00 2001 From: yann Date: Wed, 2 Jul 2025 15:06:46 +0200 Subject: [PATCH 4/8] first try to get session cookie --- tests/conftest.py | 5 ++++- tests/test_purchase.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 50e7972..50ec543 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,7 @@ import pytest from server import app +from bs4 import BeautifulSoup + EMAIL1 = "admin@irontemple.com" EMAIL2 = "john@simplylift.co" @@ -12,6 +14,7 @@ def client(): @pytest.fixture def connect(client): - response = client.post('/showSummary', data={"email": EMAIL}) + response = client.post('/showSummary', data={"email": EMAIL1}) soup = BeautifulSoup(response.data, 'html.parser') + return soup diff --git a/tests/test_purchase.py b/tests/test_purchase.py index abb03e3..15b0926 100644 --- a/tests/test_purchase.py +++ b/tests/test_purchase.py @@ -1,5 +1,13 @@ from bs4 import BeautifulSoup +from flask import session -def test_should_not_when_try_more_points_than_available(connect): - print(response.data) +def test_should_not_when_try_more_points_than_available(client): + data = {"competition": "Spring Festival", "club": "Iron Temple", "places": "5"} + + # response = client.post('/book/Spring%20Festival/Iron%20Temple', data=data) + response = client.post('/purchasePlaces', data=data) + # print(BeautifulSoup(response.data, "html.parser")) + print(session) + #assert "_flashes" in session + #assert session["_flashes"] == [("message", "You don't have enough points")] From 9705789809020189069ea1aa9e861b2249f4e860 Mon Sep 17 00:00:00 2001 From: yann Date: Wed, 2 Jul 2025 15:07:28 +0200 Subject: [PATCH 5/8] works better with init --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 813b7849fe65be24b29b9ba01a7cb2726d68fb2e Mon Sep 17 00:00:00 2001 From: yann Date: Wed, 2 Jul 2025 17:27:06 +0200 Subject: [PATCH 6/8] test Ok on soup --- tests/test_purchase.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_purchase.py b/tests/test_purchase.py index 15b0926..350b7a4 100644 --- a/tests/test_purchase.py +++ b/tests/test_purchase.py @@ -3,11 +3,9 @@ from flask import session def test_should_not_when_try_more_points_than_available(client): - data = {"competition": "Spring Festival", "club": "Iron Temple", "places": "5"} - - # response = client.post('/book/Spring%20Festival/Iron%20Temple', data=data) + data = {"competition": "Spring Festival", "club": "Iron Temple", "places": "6"} response = client.post('/purchasePlaces', data=data) - # print(BeautifulSoup(response.data, "html.parser")) - print(session) - #assert "_flashes" in session - #assert session["_flashes"] == [("message", "You don't have enough points")] + soup = BeautifulSoup(response.data, "html.parser") + print(soup.li.text) + assert "You don't have enough points" == soup.li.text + From 0370de60e0a7c27ada0c27202d91c01d2873f448 Mon Sep 17 00:00:00 2001 From: yann Date: Thu, 3 Jul 2025 11:41:17 +0200 Subject: [PATCH 7/8] added ok and nok on points --- server.py | 7 +++---- templates/welcome.html | 6 +++--- tests/conftest.py | 10 +++++++++- tests/test_connection.py | 2 ++ tests/test_purchase.py | 20 ++++++++++++++------ 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/server.py b/server.py index b0d68c3..f9c76cd 100644 --- a/server.py +++ b/server.py @@ -29,7 +29,7 @@ def showSummary(): club = [club for club in clubs if club['email'] == request.form['email']] if club: return render_template('welcome.html', club=club[0], competitions=competitions) - flash("The email isn't found") + flash("Sorry, that email wasn't found") return redirect(url_for('index')) @app.route('/book//') @@ -53,11 +53,10 @@ def purchasePlaces(): competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired if competition['numberOfPlaces'] < 0: competition['numberOfPlaces'] = 0 - flash('Great-booking complete!') + flash("Great-booking complete!") else: flash("You don't have enough points") - return render_template('welcome.html', club=club, - competitions=competitions) + return render_template('welcome.html', club=club, competitions=competitions) diff --git a/templates/welcome.html b/templates/welcome.html index ff6b261..da2841d 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -5,7 +5,7 @@ Summary | GUDLFT Registration -

Welcome, {{club['email']}}

Logout +

Welcome, {{club['email']}}

Logout {% with messages = get_flashed_messages()%} {% if messages %} @@ -15,7 +15,7 @@ {% endfor %} {% endif%} - Points available: {{club['points']}} + Points available: {{club['points']}}

Competitions:

    {% for comp in competitions%} @@ -33,4 +33,4 @@ {%endwith%} - \ No newline at end of file + diff --git a/tests/conftest.py b/tests/conftest.py index 50ec543..ab309ae 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,13 +5,21 @@ from bs4 import BeautifulSoup EMAIL1 = "admin@irontemple.com" EMAIL2 = "john@simplylift.co" +@pytest.fixture +def club1(): + data = {"competition": "Spring Festival", "club": "Iron Temple"} + return data + +@pytest.fixture +def club2(): + data = {"competition": "Fall Classic", "club": "Iron Temple"} + return data @pytest.fixture def client(): with app.test_client() as client: yield client - @pytest.fixture def connect(client): response = client.post('/showSummary', data={"email": EMAIL1}) diff --git a/tests/test_connection.py b/tests/test_connection.py index 22b664f..50c2f9b 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -10,6 +10,7 @@ def test_should_status_code_ok(client): def test_should_display_sorry_with_unknown_email(client): email = "test@test.com" response = client.post('/showSummary', data={"email": email}) + print(session) assert "_flashes" in session assert session["_flashes"] == [("message", "Sorry, that email wasn't found")] @@ -17,6 +18,7 @@ def test_should_display_sorry_with_unknown_email(client): def test_shoul_display_page_on_known_email(client): email = "admin@irontemple.com" response = client.post('/showSummary', data={"email": email}) + print(session) soup = BeautifulSoup(response.data, 'html.parser') assert soup.h2.text == "Welcome, "+email diff --git a/tests/test_purchase.py b/tests/test_purchase.py index 350b7a4..3dbca62 100644 --- a/tests/test_purchase.py +++ b/tests/test_purchase.py @@ -2,10 +2,18 @@ from bs4 import BeautifulSoup from flask import session -def test_should_not_when_try_more_points_than_available(client): - data = {"competition": "Spring Festival", "club": "Iron Temple", "places": "6"} - response = client.post('/purchasePlaces', data=data) - soup = BeautifulSoup(response.data, "html.parser") - print(soup.li.text) - assert "You don't have enough points" == soup.li.text +class TestPoints: + + def test_should_nok_when_too_much_points(self, client, connect, club1): + points = int(connect.span.text) + club1.update({"places": points+1}) + response = client.post('/purchasePlaces', data=club1) + soup = BeautifulSoup(response.data, "html.parser") + assert "You don't have enough points" == soup.li.text + def test_should_ok_when_enough_points(self, client, connect, club1): + points = int(connect.span.text) + data = club1.update({"places": points-1}) + response = client.post('/purchasePlaces', data=club1) + soup = BeautifulSoup(response.data, "html.parser") + assert "Great-booking complete!" == soup.li.text From 79a6b00401c599d1ce4cb7b5ea5c5d8ede3c7310 Mon Sep 17 00:00:00 2001 From: yann Date: Mon, 7 Jul 2025 10:27:54 +0200 Subject: [PATCH 8/8] removed print --- tests/test_connection.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 50c2f9b..22b664f 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -10,7 +10,6 @@ def test_should_status_code_ok(client): def test_should_display_sorry_with_unknown_email(client): email = "test@test.com" response = client.post('/showSummary', data={"email": email}) - print(session) assert "_flashes" in session assert session["_flashes"] == [("message", "Sorry, that email wasn't found")] @@ -18,7 +17,6 @@ def test_should_display_sorry_with_unknown_email(client): def test_shoul_display_page_on_known_email(client): email = "admin@irontemple.com" response = client.post('/showSummary', data={"email": email}) - print(session) soup = BeautifulSoup(response.data, 'html.parser') assert soup.h2.text == "Welcome, "+email