66@pytest .fixture
77def client ():
88 app .config ['TESTING' ] = True
9- app .secret_key = "test" # Nécessaire pour flash
9+ app .secret_key = "test"
1010 with app .test_client () as client :
1111 yield client
1212
@@ -16,7 +16,6 @@ def test_booking_past_competition(client, monkeypatch):
1616 past_date = (datetime .now () - timedelta (days = 1 )).strftime ("%Y-%m-%d %H:%M:%S" )
1717 test_competition = {"name" : "Past Competition" , "numberOfPlaces" : "10" , "date" : past_date }
1818 test_club = {
"name" :
"Test Club" ,
"email" :
"[email protected] " ,
"points" :
"15" }
19-
2019 monkeypatch .setattr ("server.clubs" , [test_club ])
2120 monkeypatch .setattr ("server.competitions" , [test_competition ])
2221
@@ -35,6 +34,26 @@ def test_booking_past_competition(client, monkeypatch):
3534 # Vérifie que les points du club n'ont pas changé
3635 assert test_club ["points" ] == "15"
3736
37+
38+ def test_booking_more_than_12_places (client , monkeypatch ):
39+ test_club = {
"name" :
"Test Club" ,
"email" :
"[email protected] " ,
"points" :
"50" }
40+ test_competition = {"name" : "Test Competition" , "numberOfPlaces" : "25" , "date" : "2025-12-12 10:00:00" }
41+ monkeypatch .setattr ("server.clubs" , [test_club ])
42+ monkeypatch .setattr ("server.competitions" , [test_competition ])
43+
44+ response = client .post ("/purchasePlaces" , data = {
45+ "competition" : "Test Competition" ,
46+ "club" : "Test Club" ,
47+ "places" : "13" # > 12 → doit déclencher le bloc
48+ }, follow_redirects = True )
49+
50+ # Vérifie que le message flash est bien là
51+ assert b"you can not book more than 12 places" in response .data
52+ # Vérifie que les données n'ont pas été modifiées
53+ assert test_competition ["numberOfPlaces" ] == "25"
54+ assert test_club ["points" ] == "50"
55+
56+
3857def test_competition_places_are_decreased (client , monkeypatch ):
3958 # Club avec assez de points
4059 test_club = {
"name" :
"Test Club" ,
"email" :
"[email protected] " ,
"points" :
"20" }
@@ -53,4 +72,5 @@ def test_competition_places_are_decreased(client, monkeypatch):
5372 }, follow_redirects = True )
5473
5574 # Vérifie que la compétition a bien été mise à jour
56- assert test_competition ["numberOfPlaces" ] == 7 # 10 - 3
75+ assert test_competition ["numberOfPlaces" ] == 7 # 10 - 3
76+
0 commit comments