From 57a5dfb8d8f0c66c854a994f22df4b2571f91292 Mon Sep 17 00:00:00 2001 From: yann Date: Fri, 11 Jul 2025 09:17:07 +0200 Subject: [PATCH] refactor dir, added integration test for feature --- templates/points.html | 37 ++++++++++++++----- tests/integration_tests/__init__.py | 0 tests/integration_tests/test_board_update.py | 36 ++++++++++++++++++ ...test_book_old.py => test_ward_book_old.py} | 0 tests/unit_tests/__init__.py | 0 tests/{ => unit_tests}/test_board.py | 4 +- tests/unit_tests/test_comp_date.py | 22 +++++++++++ tests/{ => unit_tests}/test_connection.py | 0 tests/{ => unit_tests}/test_purchase.py | 21 ----------- tests/{ => unit_tests}/test_update.py | 0 10 files changed, 88 insertions(+), 32 deletions(-) create mode 100644 tests/integration_tests/__init__.py create mode 100644 tests/integration_tests/test_board_update.py rename tests/{test_book_old.py => test_ward_book_old.py} (100%) create mode 100644 tests/unit_tests/__init__.py rename tests/{ => unit_tests}/test_board.py (88%) create mode 100644 tests/unit_tests/test_comp_date.py rename tests/{ => unit_tests}/test_connection.py (100%) rename tests/{ => unit_tests}/test_purchase.py (74%) rename tests/{ => unit_tests}/test_update.py (100%) diff --git a/templates/points.html b/templates/points.html index abc6e53..3765437 100644 --- a/templates/points.html +++ b/templates/points.html @@ -3,17 +3,36 @@ Board of clubs and points || GUDLFT + -

Current points

- +

Board of clubs

+ + + + + + + + {% for club in clubs %} + + + + + {% endfor %} + +
+ Points per club +
ClubPoints
{{club['name']}}{{club['points']}}
Back diff --git a/tests/integration_tests/__init__.py b/tests/integration_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration_tests/test_board_update.py b/tests/integration_tests/test_board_update.py new file mode 100644 index 0000000..183cdfb --- /dev/null +++ b/tests/integration_tests/test_board_update.py @@ -0,0 +1,36 @@ +from tests import conftest +from server import loadClubs +from bs4 import BeautifulSoup + +class TestBoardPointsUpdate: + + def test_should_board_be_updated_after_booking(self, client): + ''' + test if the board is well displayed, and retrive points displayed for first club + then connect with this club email and book places + then check on board if the balance reflect the points decrease + ''' + nb_places = 10 + data = { + "competition": "Fall Classic", + "club": "Simply Lift", + "places": nb_places, + } + list_club = loadClubs() + # connect on board and check if points for first club are equal to points in DB (json) + response = client.get('/points') + soup = BeautifulSoup(response.data, "html.parser") + points1 = soup.find(id='points').text + assert response.status_code == 200 + assert points1 == list_club[0]['points'] + # then connect with mail of first club + connect = client.post('/showSummary', data={"email":"john@simplylift.co"}) + assert connect.status_code == 200 + # then book places + response = client.post('purchasePlaces', data=data) + assert f"Great ! "+str(nb_places)+" places booked for "+data['competition'] in response.data.decode() + # then check points on board + check_board = client.get('/points') + soup = BeautifulSoup(check_board.data, "html.parser") + points = soup.find(id='points').text + assert int(points) == int(points1)-10 diff --git a/tests/test_book_old.py b/tests/test_ward_book_old.py similarity index 100% rename from tests/test_book_old.py rename to tests/test_ward_book_old.py diff --git a/tests/unit_tests/__init__.py b/tests/unit_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_board.py b/tests/unit_tests/test_board.py similarity index 88% rename from tests/test_board.py rename to tests/unit_tests/test_board.py index 6fbb33e..286daea 100644 --- a/tests/test_board.py +++ b/tests/unit_tests/test_board.py @@ -18,7 +18,7 @@ class TestBoardDisplayPoints: list_club = loadClubs() response = client.get('/points') soup = BeautifulSoup(response.data, "html.parser") - li = soup.find_all("li") - assert len(li) == len(list_club) + tr = soup.find_all("tr") + assert len(tr) == len(list_club) diff --git a/tests/unit_tests/test_comp_date.py b/tests/unit_tests/test_comp_date.py new file mode 100644 index 0000000..6fb6a49 --- /dev/null +++ b/tests/unit_tests/test_comp_date.py @@ -0,0 +1,22 @@ + +class TestDate: + ''' + test the booking for the past competitions + ''' + + def test_should_not_display_book_link_for_past_competitions(self, connect): + ''' + test that the booking link isn't displayed when competition date is older than today + ''' + li = connect.find_all("li") + assert not li[0].a + assert li[1].a + + def test_forged_url_on_past_competition_should_raise_flash(self, client): + ''' + test that a flash warning occur when trying to connect to an URL on an old competition + ''' + url = '/book/Spring Festival/Iron Temple' + response = client.get(url) + assert "You cannot book for a past competition" in response.data.decode() + diff --git a/tests/test_connection.py b/tests/unit_tests/test_connection.py similarity index 100% rename from tests/test_connection.py rename to tests/unit_tests/test_connection.py diff --git a/tests/test_purchase.py b/tests/unit_tests/test_purchase.py similarity index 74% rename from tests/test_purchase.py rename to tests/unit_tests/test_purchase.py index f377fdd..9a67889 100644 --- a/tests/test_purchase.py +++ b/tests/unit_tests/test_purchase.py @@ -57,24 +57,3 @@ class TestPlaces: assert "You already booked 12 places for "+club2['competition'] == soup.li.text -class TestDate: - ''' - test the booking for the past competitions - ''' - - def test_should_not_display_book_link_for_past_competitions(self, connect): - ''' - test that the booking link isn't displayed when competition date is older than today - ''' - li = connect.find_all("li") - assert not li[0].a - assert li[1].a - - def test_forged_url_on_past_competition_should_raise_flash(self, client): - ''' - test that a flash warning occur when trying to connect to an URL on an old competition - ''' - url = '/book/Spring Festival/Iron Temple' - response = client.get(url) - assert "You cannot book for a past competition" in response.data.decode() - diff --git a/tests/test_update.py b/tests/unit_tests/test_update.py similarity index 100% rename from tests/test_update.py rename to tests/unit_tests/test_update.py