|
| 1 | +import pytest |
| 2 | +from server import app |
| 3 | + |
| 4 | +@pytest.fixture |
| 5 | +def client(): |
| 6 | + app.config['TESTING'] = True |
| 7 | + with app.test_client() as client: |
| 8 | + yield client |
| 9 | + |
| 10 | +def test_purchase_places_more_than_points(client, monkeypatch): |
| 11 | + # Simuler un club avec seulement 2 points |
| 12 | + test_club = {"name": "Test Club", "email": "test@club.com", "points": "2"} |
| 13 | + test_competition = {"name": "Test Competition", "numberOfPlaces": "10", "date": "2025-12-12 10:00:00"} |
| 14 | + |
| 15 | + # Patch les données dans server.py |
| 16 | + monkeypatch.setattr("server.clubs", [test_club]) |
| 17 | + monkeypatch.setattr("server.competitions", [test_competition]) |
| 18 | + |
| 19 | + # Envoyer un formulaire avec 5 places (plus que les 2 points disponibles) |
| 20 | + response = client.post("/purchasePlaces", data={ |
| 21 | + "competition": "Test Competition", |
| 22 | + "club": "Test Club", |
| 23 | + "places": "5" |
| 24 | + }, follow_redirects=True) |
| 25 | + |
| 26 | + # Vérifier que le message d'erreur s'affiche |
| 27 | + assert b"you can not book more than available points" in response.data |
| 28 | + |
| 29 | +def test_purchase_places_success(client, monkeypatch): |
| 30 | + test_club = {"name": "Test Club", "email": "test@club.com", "points": "10"} |
| 31 | + test_competition = {"name": "Test Competition", "numberOfPlaces": "15", "date": "2025-12-12 10:00:00"} |
| 32 | + |
| 33 | + monkeypatch.setattr("server.clubs", [test_club]) |
| 34 | + monkeypatch.setattr("server.competitions", [test_competition]) |
| 35 | + |
| 36 | + response = client.post("/purchasePlaces", data={ |
| 37 | + "competition": "Test Competition", |
| 38 | + "club": "Test Club", |
| 39 | + "places": "3" |
| 40 | + }, follow_redirects=True) |
| 41 | + |
| 42 | + assert b"Great-booking complete!" in response.data |
0 commit comments