refactor dir, added integration test for feature

This commit is contained in:
2025-07-11 09:17:07 +02:00
parent 297468e4ad
commit 57a5dfb8d8
10 changed files with 88 additions and 32 deletions

View File

@@ -3,17 +3,36 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Board of clubs and points || GUDLFT</title> <title>Board of clubs and points || GUDLFT</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
table.center {
margin-left: auto;
margin-right: auto;
}
</style>
</head> </head>
<body> <body>
<h2>Current points</h2> <h2>Board of clubs</h2>
<ul> <table class="center">
<caption>
Points per club
</caption>
<thead>
<th scope="col">Club</th>
<th scope="col">Points</th>
</thead>
<tbody>
{% for club in clubs %} {% for club in clubs %}
<li><strong>club : </strong> {{club['name']}} </br> <tr>
<strong>Points : </strong>{{club['points']}}</br> <td id="{{club['name']}}">{{club['name']}}</td>
</br> <td id="points">{{club['points']}}</td>
</li> </tr>
{% endfor %} {% endfor %}
</ul> </tbody>
</table>
<a href="{{ url_for('index') }}"> Back </a> <a href="{{ url_for('index') }}"> Back </a>
</body> </body>
</html> </html>

View File

View File

@@ -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

View File

View File

@@ -18,7 +18,7 @@ class TestBoardDisplayPoints:
list_club = loadClubs() list_club = loadClubs()
response = client.get('/points') response = client.get('/points')
soup = BeautifulSoup(response.data, "html.parser") soup = BeautifulSoup(response.data, "html.parser")
li = soup.find_all("li") tr = soup.find_all("tr")
assert len(li) == len(list_club) assert len(tr) == len(list_club)

View File

@@ -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()

View File

@@ -57,24 +57,3 @@ class TestPlaces:
assert "You already booked 12 places for "+club2['competition'] == soup.li.text 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()