forked from OpenClassrooms-Student-Center/Python_Testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
189 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from datetime import datetime | ||
|
||
|
||
def get_past_competitions(competitions_list: list): | ||
return [ | ||
comp for comp in competitions_list if | ||
datetime.fromisoformat(comp['date']) < datetime.now() | ||
] | ||
|
||
|
||
def get_future_competitions(competitions_list: list): | ||
return [ | ||
comp for comp in competitions_list if | ||
datetime.fromisoformat(comp['date']) > datetime.now() | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from flask.testing import FlaskClient | ||
from unittest.mock import patch | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def past_competitions_only(): | ||
return patch('app.server.competitions', [ | ||
{ | ||
"name": "past_competition", | ||
"date": "2020-03-27 10:00:00", | ||
"numberOfPlaces": "5" | ||
}, | ||
]) | ||
|
||
|
||
@pytest.fixture | ||
def future_competitions_only(): | ||
return patch('app.server.competitions', [ | ||
{ | ||
"name": "future_competition", | ||
"date": "2099-03-27 10:00:00", | ||
"numberOfPlaces": "5" | ||
}, | ||
]) | ||
|
||
|
||
def test_past_competitions_are_not_bookable(client: FlaskClient, variable_clubs_mock, past_competitions_only): | ||
|
||
with variable_clubs_mock, past_competitions_only: | ||
|
||
response = client.post( | ||
"/showSummary", | ||
data={ | ||
"email": "club1@domain.co" | ||
} | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert b"past_competition" in response.data | ||
assert b"2020-03-27 10:00:00" in response.data | ||
assert b"Number of Places: 5" not in response.data | ||
|
||
|
||
def test_future_competitions_are_bookable(client: FlaskClient, variable_clubs_mock, future_competitions_only): | ||
|
||
with variable_clubs_mock, future_competitions_only: | ||
|
||
response = client.post( | ||
"/showSummary", | ||
data={ | ||
"email": "club1@domain.co" | ||
} | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert b"future_competition" in response.data | ||
assert b"2099-03-27 10:00:00" in response.data | ||
assert b"Number of Places: 5" in response.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from app import utils | ||
from tests.conftest import TEST_COMPETITIONS | ||
|
||
|
||
def test_get_past_competitions(): | ||
past_competitions = utils.get_past_competitions(TEST_COMPETITIONS) | ||
assert len(past_competitions) == 1 | ||
|
||
|
||
def test_get_future_competitions(): | ||
future_competitions = utils.get_future_competitions(TEST_COMPETITIONS) | ||
assert len(future_competitions) == 3 |