Skip to content

Commit 60dcbf4

Browse files
author
laurence
committed
Merge remote-tracking branch 'origin/bug/book-no-more-than-12-places'
2 parents 2aa49d4 + 4c2c3e4 commit 60dcbf4

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
from datetime import datetime
3-
43
from flask import Flask,render_template,request,redirect,flash,url_for
54

65

@@ -48,6 +47,9 @@ def purchasePlaces():
4847
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
4948
club = [c for c in clubs if c['name'] == request.form['club']][0]
5049
placesRequired = int(request.form['places'])
50+
if placesRequired > 12:
51+
flash("you can not book more than 12 places")
52+
return render_template('welcome.html', club=club, competitions=competitions)
5153
if datetime.strptime(competition['date'], "%Y-%m-%d %H:%M:%S") < datetime.now():
5254
flash("You cannot book place in past competition")
5355
return render_template('welcome.html', club=club, competitions=competitions)

templates/booking.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h2>{{competition['name']}}</h2>
1010
<form action="/purchasePlaces" method="post">
1111
<input type="hidden" name="club" value="{{club['name']}}">
1212
<input type="hidden" name="competition" value="{{competition['name']}}">
13-
<label for="places">How many places?</label><input type="number" name="places" id=""/>
13+
<label for="places">How many places?</label><input type="number" min="0" max="12" name="places" id=""/>
1414
<button type="submit">Book</button>
1515
</form>
1616
</body>

test/tests_unitaires/test_server.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@pytest.fixture
77
def 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": "test@club.com", "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": "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+
3857
def test_competition_places_are_decreased(client, monkeypatch):
3958
# Club avec assez de points
4059
test_club = {"name": "Test Club", "email": "test@club.com", "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

Comments
 (0)