Skip to content

Commit

Permalink
Correction pour l'issue OpenClassrooms-Student-Center#5
Browse files Browse the repository at this point in the history
  • Loading branch information
DomninBenoit committed Dec 12, 2023
1 parent 12951b5 commit 6562f81
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions competitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"date": "2020-03-27 10:00:00",
"numberOfPlaces": "25"
},
{
"name": "Summer Festival",
"date": "2024-03-27 10:00:00",
"numberOfPlaces": "25"
},
{
"name": "Fall Classic",
"date": "2020-10-22 13:30:00",
Expand Down
8 changes: 8 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from flask import (Flask, render_template,
request, redirect, flash, url_for)
from datetime import datetime


def loadClubs():
Expand Down Expand Up @@ -39,6 +40,13 @@ def showSummary():
def book(competition,club):
foundClub = [c for c in clubs if c['name'] == club][0]
foundCompetition = [c for c in competitions if c['name'] == competition][0]

competition_date = datetime.strptime(foundCompetition['date'], "%Y-%m-%d %H:%M:%S")

if competition_date < datetime.now():
flash("Cette compétition est déjà passée et ne peut pas être réservée.")
return render_template('welcome.html', club=club, competitions=competitions)

if foundClub and foundCompetition:
return render_template('booking.html',club=foundClub,competition=foundCompetition)
else:
Expand Down
9 changes: 9 additions & 0 deletions test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ def test_purchase_more_max_places(client):
# 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

def test_booking_past_competition(client):
club_name = "Simply Lift"
past_competition_name = "Spring Festival"

response = client.get(f'/book/{past_competition_name}/{club_name}')
assert "Cette compétition est déjà passée et ne peut pas être réservée." in response.get_data(as_text=True)


0 comments on commit 6562f81

Please sign in to comment.