Skip to content

Commit

Permalink
Correction pour l'issue OpenClassrooms-Student-Center#3
Browse files Browse the repository at this point in the history
  • Loading branch information
DomninBenoit committed Dec 11, 2023
1 parent ddf0e9a commit 12951b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ def purchasePlaces():
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places'])

if placesRequired > int(club["points"]):
flash(f'Vous n avez pas assez de points : seulement {club["points"]} réservés.')
placesRequired = int(club["points"])
return render_template('welcome.html', club=club, competitions=competitions)

if placesRequired > 12:
flash("Impossible de réserver plus de 12 places")
return render_template('welcome.html', club=club, competitions=competitions)

competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
club['points'] = int(club['points']) - placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)

Expand Down
24 changes: 24 additions & 0 deletions test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,27 @@ def test_redeem_more_points_than_available(client):
# Vérifiez que les points du club n'ont pas été déduits incorrectement
updated_club = [c for c in loadClubs() if c['name'] == club_name][0]
assert int(updated_club['points']) == initial_points

def test_purchase_more_max_places(client):
club_name = "Simply Lift"
competition_name = "Spring Festival"
clubs = loadClubs()
competitions = loadCompetitions()

# Assurez-vous d'avoir suffisamment de places disponibles pour le test
competition = [comp for comp in competitions if comp['name'] == competition_name][0]
initial_number_of_places = int(competition['numberOfPlaces'])

# Simulez l'envoi d'un formulaire avec une réservation de 13 places (plus que la limite de 12)
response = client.post('/purchasePlaces', data={
'club': club_name,
'competition': competition_name,
'places': 13
})

# Vérifiez que la transaction n'est pas autorisée et qu'un message d'erreur est affiché
assert 'Impossible de réserver plus de 12 places' in response.get_data(as_text=True)

# Vérifiez également que le nombre de places disponibles pour la compétition n'a pas été réduit
updated_competition = [comp for comp in loadCompetitions() if comp['name'] == competition_name][0]
assert int(updated_competition['numberOfPlaces']) == initial_number_of_places

0 comments on commit 12951b5

Please sign in to comment.