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

View File

@@ -0,0 +1,24 @@
from bs4 import BeautifulSoup
from server import loadClubs
class TestBoardDisplayPoints:
def test_should_get_200(self, client):
'''
test if the page is retrieved
'''
response = client.get('/points')
assert response.status_code == 200
def test_should_display_right_size_list(self, client):
'''
test if the list of club displayed and in DB have the same size
'''
list_club = loadClubs()
response = client.get('/points')
soup = BeautifulSoup(response.data, "html.parser")
tr = soup.find_all("tr")
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

@@ -0,0 +1,22 @@
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')
welcome = "Welcome, "+email
assert welcome in response.data.decode()

View File

@@ -0,0 +1,59 @@
from bs4 import BeautifulSoup
from flask import session
class TestPoints:
'''
testing both case, book with and without enough points
'''
def test_should_nok_when_too_much_points(self, client, connect, club2):
'''
test booking an amount of places greater than the available points
'''
points = int(connect.span.text)
club2.update({"places": points+1})
response = client.post('/purchasePlaces', data=club2)
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, club2):
'''
test booking with enough points
'''
points = int(connect.span.text)
# One remaining point after that :
club2.update({"places": points-1})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert f"Great ! "+str(points-1)+" places booked for "+club2['competition'] == soup.li.text
class TestPlaces:
'''
test the booking limit of 12 places
'''
def test_should_refuse_more_12_once(self, client, club2):
'''
test to book more than 12 places in one shot
'''
club2.update({"places": 13})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert "You can't book more than 12 places" == soup.li.text
def test_should_refuse_more_12_total(self, client, club2):
'''
test to book more than 12 places in a two-part reservation
'''
club2.update({"places": 1})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert "Great ! 1 places booked for "+club2['competition'] == soup.li.text
club2.update({"places": 12})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert "You already booked 12 places for "+club2['competition'] == soup.li.text

View File

@@ -0,0 +1,12 @@
class TestPointsUpdate:
def test_should_not_be_ok_the_second_time(self, connect, client, club2):
'''
this books an amount of points-1 places
then test if 1 points remains displayed on page
'''
points = int(connect.span.text)
club2.update({"places": points-1})
response = client.post('/purchasePlaces', data=club2)
assert f"Great ! {points-1} places booked for {club2['competition']}" in response.data.decode()