Skip to content

Commit

Permalink
Correction pour l'issue OpenClassrooms-Student-Center#2
Browse files Browse the repository at this point in the history
  • Loading branch information
DomninBenoit committed Dec 11, 2023
1 parent 27a4023 commit ddf0e9a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ 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"])
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)
Expand Down
23 changes: 23 additions & 0 deletions test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@ def test_email_introuvable(client):
response = client.post('/showSummary', data={'email': 'emailinexistant@example.com'})
assert response.status_code == 200
assert 'email introuvable' in response.data.decode('utf-8')


def test_redeem_more_points_than_available(client):
club_name = "Iron Temple"
competition_name = "Fall Classic"
clubs = loadClubs()
club = [c for c in clubs if c['name'] == club_name][0]
initial_points = int(club['points'])
points_to_redeem = initial_points + 10 # Un nombre supérieur aux points disponibles

# Simulez l'envoi d'un formulaire avec plus de points que disponibles
response = client.post('/purchasePlaces', data={
'club': club_name,
'competition': competition_name,
'places': points_to_redeem
})

# Vérifie que le message d'erreur est affiché
assert f'Vous n avez pas assez de points : seulement {initial_points} réservés.' in response.get_data(as_text=True)

# 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

0 comments on commit ddf0e9a

Please sign in to comment.