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.
- Loading branch information
Showing
3 changed files
with
95 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ bin | |
include/ | ||
Lib/ | ||
Scripts/ | ||
tests/ | ||
.Python | ||
.envrc | ||
__pycache__/ | ||
pyvenv.cfg | ||
pyvenv.cfg | ||
.pytest_cache/ |
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 |
---|---|---|
|
@@ -11,20 +11,58 @@ def client(): | |
@pytest.fixture | ||
def clubs(): | ||
clubs = [ | ||
{ | ||
"name":"Simply Lift", | ||
"email":"[email protected]", | ||
"points":"13" | ||
}, | ||
{ | ||
"name":"Iron Temple", | ||
"email": "[email protected]", | ||
"points":"4" | ||
}, | ||
{ "name":"She Lifts", | ||
"email": "[email protected]", | ||
"points":"12" | ||
} | ||
] | ||
{ | ||
"name":"Simply Lift", | ||
"email":"[email protected]", | ||
"points":"13" | ||
}, | ||
{ | ||
"name":"Iron Temple", | ||
"email": "[email protected]", | ||
"points":"4" | ||
}, | ||
{ "name":"She Lifts", | ||
"email": "[email protected]", | ||
"points":"12" | ||
} | ||
] | ||
|
||
return clubs | ||
return clubs | ||
|
||
@pytest.fixture | ||
def single_club(): | ||
club = { | ||
"name":"Simply Lift", | ||
"email":"[email protected]", | ||
"points":"13" | ||
} | ||
|
||
return club | ||
|
||
@pytest.fixture | ||
def single_competition(): | ||
competition = { | ||
"name": "Spring Festival", | ||
"date": "2020-03-27 10:00:00", | ||
"numberOfPlaces": "25" | ||
} | ||
|
||
return competition | ||
|
||
|
||
@pytest.fixture | ||
def competitions(): | ||
competitions = [ | ||
{ | ||
"name": "Spring Festival", | ||
"date": "2020-03-27 10:00:00", | ||
"numberOfPlaces": "25" | ||
}, | ||
{ | ||
"name": "Fall Classic", | ||
"date": "2020-10-22 13:30:00", | ||
"numberOfPlaces": "13" | ||
} | ||
] | ||
|
||
return competitions |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import pytest | ||
from server import app | ||
from tests.conftest import client, clubs | ||
from tests.conftest import client, clubs, single_club, single_competition, competitions | ||
|
||
|
||
class TestShowSummary: | ||
|
@@ -14,4 +14,41 @@ def test_login_with_invalid_email(self, client, clubs): | |
app.config["clubs"] = clubs | ||
response = client.post("/showSummary", data={"email": "[email protected]"}) | ||
|
||
assert b"Email not found. Please try a valid email." in response.data | ||
assert b"Email not found. Please try a valid email." in response.data | ||
|
||
|
||
class TestPurchasePlaces: | ||
def test_purchase_places_with_enough_points(self, client, single_club, single_competition) : | ||
competition = single_competition["name"] | ||
club = single_club["name"] | ||
club_points = int(single_club["points"]) | ||
places_booked = 5 | ||
|
||
response = client.post("/purchasePlaces", data={"club": club, "competition": competition, "places": places_booked}) | ||
|
||
assert response.status_code == 200 | ||
assert "Great-booking complete!" in response.data.decode() | ||
assert "Points available: 8" in response.data.decode() | ||
|
||
def test_purchase_places_with_excessive_points(self, client, single_club, single_competition) : | ||
competition = single_competition["name"] | ||
club = single_club["name"] | ||
club_points = int(single_club["points"]) | ||
places_booked = 20 | ||
|
||
response = client.post("/purchasePlaces", data={"club": club, "competition": competition, "places": places_booked}) | ||
|
||
assert "have enough points to book this quantity. Please try again." in response.data.decode() | ||
assert "Points available: 8" in response.data.decode() | ||
|
||
def test_purchase_places_with_negative_input(self, client, single_club, single_competition) : | ||
competition = single_competition["name"] | ||
club = single_club["name"] | ||
club_points = int(single_club["points"]) | ||
places_booked = -2 | ||
|
||
response = client.post("/purchasePlaces", data={"club": club, "competition": competition, "places": places_booked}) | ||
|
||
assert "This is not a correct value. Please try again." in response.data.decode() | ||
assert "Points available: 8" in response.data.decode() | ||
|