Skip to content

Commit

Permalink
Test and fix issue OpenClassrooms-Student-Center#4
Browse files Browse the repository at this point in the history
  • Loading branch information
SelHel committed Jun 13, 2022
1 parent 5d193b4 commit 74221d1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion competitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"name": "Fall Classic",
"date": "2020-10-22 13:30:00",
"date": "2022-10-22 13:30:00",
"numberOfPlaces": "13"
}
]
Expand Down
6 changes: 5 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ 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]
date_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if foundClub and foundCompetition:
return render_template('booking.html',club=foundClub,competition=foundCompetition)
if foundCompetition['date'] < date_time:
flash("You cannot book places in past competition")
return render_template("welcome.html", club=club, competitions=competitions)
return render_template('booking.html', club=foundClub, competition=foundCompetition)
else:
flash("Something went wrong-please try again")
return render_template('welcome.html', club=club, competitions=competitions)
Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ def mock_clubs(mocker):
"points": "12"
},
]
mocker.patch.object(server, 'clubs', clubs)
mocked = mocker.patch.object(server, 'clubs', clubs)
yield mocked


@pytest.fixture
def mock_competitions(mocker):
competitions = [
{
"name": "Test Competition 1",
"date": "2023-06-07 10:00:00",
"date": "2021-06-07 10:00:00",
"numberOfPlaces": "25"
},
{
Expand All @@ -51,4 +52,5 @@ def mock_competitions(mocker):
"numberOfPlaces": "5"
}
]
mocker.patch.object(server, 'competitions', competitions)
mocked = mocker.patch.object(server, 'competitions', competitions)
yield mocked
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
"""


def test_invalid_competition_date(client, mock_clubs, mock_competitions):
club = mock_clubs[0]['name']
competition = mock_competitions[0]['name']
response = client.get(f"/book/{competition}/{club}")
assert response.status_code == 200
assert "You cannot book places in past competition" in response.data.decode()


def test_valid_competition_date(client, mock_clubs, mock_competitions):
club = mock_clubs[0]['name']
competition = mock_competitions[1]['name']
response = client.get(f"/book/{competition}/{club}")
assert response.status_code == 200






Expand Down

0 comments on commit 74221d1

Please sign in to comment.