1
+ import sys
2
+ import os
3
+ sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' )))
4
+ import pytest
5
+ from server import app , clubs , competitions
6
+ import json
7
+
8
+ @pytest .fixture
9
+ def client ():
10
+ app .config ['TESTING' ] = True
11
+ with app .test_client () as client :
12
+ yield client
13
+
14
+ def test_points_deduction (client ):
15
+ """Test que les points sont bien déduits après réservation"""
16
+ # Données de test
17
+ club_name = "Simply Lift"
18
+ competition_name = "Spring Festival"
19
+ places_required = 2
20
+
21
+ # Points initiaux
22
+ initial_points = int (next (c ['points' ] for c in clubs if c ['name' ] == club_name ))
23
+
24
+ # Faire la requête de réservation
25
+ response = client .post ('/purchasePlaces' , data = {
26
+ 'competition' : competition_name ,
27
+ 'club' : club_name ,
28
+ 'places' : str (places_required )
29
+ })
30
+
31
+ # Vérifications
32
+ assert response .status_code == 200
33
+ assert b"Great-booking complete!" in response .data
34
+
35
+ # Vérifier la mise à jour des points
36
+ updated_points = int (next (c ['points' ] for c in clubs if c ['name' ] == club_name ))
37
+ assert updated_points == initial_points - places_required
38
+
39
+ def test_insufficient_points (client ):
40
+ """Test que les points ne sont pas déduits si réservation impossible"""
41
+ # Données de test
42
+ club_name = "Iron Temple" # 4 points initialement
43
+ competition_name = "Spring Festival"
44
+ places_required = 5 # Plus que les points disponibles
45
+
46
+ # Points initiaux
47
+ initial_points = int (next (c ['points' ] for c in clubs if c ['name' ] == club_name ))
48
+
49
+ # Faire la requête de réservation
50
+ response = client .post ('/purchasePlaces' , data = {
51
+ 'competition' : competition_name ,
52
+ 'club' : club_name ,
53
+ 'places' : str (places_required )
54
+ })
55
+
56
+ # Vérifications
57
+ assert response .status_code == 400
58
+ # Vérifie soit la version encodée HTML soit décodée
59
+ assert (b"Your club doesn't have enough points" in response .data or
60
+ b"Your club doesn't have enough points" in response .data )
61
+
62
+ # Vérifier que les points n'ont pas changé
63
+ current_points = int (next (c ['points' ] for c in clubs if c ['name' ] == club_name ))
64
+ assert current_points == initial_points
0 commit comments