6
6
@pytest .fixture
7
7
def client ():
8
8
app .config ['TESTING' ] = True
9
- app .secret_key = "test" # Nécessaire pour flash
9
+ app .secret_key = "test"
10
10
with app .test_client () as client :
11
11
yield client
12
12
@@ -16,7 +16,6 @@ def test_booking_past_competition(client, monkeypatch):
16
16
past_date = (datetime .now () - timedelta (days = 1 )).strftime ("%Y-%m-%d %H:%M:%S" )
17
17
test_competition = {"name" : "Past Competition" , "numberOfPlaces" : "10" , "date" : past_date }
18
18
test_club = {"name" : "Test Club" , "email" : "test@club.com" , "points" : "15" }
19
-
20
19
monkeypatch .setattr ("server.clubs" , [test_club ])
21
20
monkeypatch .setattr ("server.competitions" , [test_competition ])
22
21
@@ -35,6 +34,26 @@ def test_booking_past_competition(client, monkeypatch):
35
34
# Vérifie que les points du club n'ont pas changé
36
35
assert test_club ["points" ] == "15"
37
36
37
+
38
+ def test_booking_more_than_12_places (client , monkeypatch ):
39
+ test_club = {"name" : "Test Club" , "email" : "test@club.com" , "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
+
38
57
def test_competition_places_are_decreased (client , monkeypatch ):
39
58
# Club avec assez de points
40
59
test_club = {"name" : "Test Club" , "email" : "test@club.com" , "points" : "20" }
@@ -53,4 +72,5 @@ def test_competition_places_are_decreased(client, monkeypatch):
53
72
}, follow_redirects = True )
54
73
55
74
# 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