Skip to content

Commit

Permalink
clubs cannot book more than allowed/available (#2 and OpenClassrooms-…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeammet committed Dec 28, 2021
1 parent 22dc4f1 commit c0caa41
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 33 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
bin
include
lib
.Python
.envrc
__pycache__
venv/
bin
include
lib
.Python
.envrc
__pycache__
venv/
.pytest_cache
48 changes: 24 additions & 24 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GUDLFT Registration</title>
</head>
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
{% with messages = get_flashed_messages()%}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{% endif%}
{%endwith%}
Please enter your secretary email to continue:
<form action="showSummary" method="post">
<label for="email">Email:</label>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
</body>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GUDLFT Registration</title>
</head>
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
{% with messages = get_flashed_messages()%}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{% endif%}
{%endwith%}
Please enter your secretary email to continue:
<form action="showSummary" method="post">
<label for="email">Email:</label>
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
</body>
</html>
17 changes: 16 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ def future_competition():
competitions = loadCompetitions('tests/test_dataset.json')
return competitions[1]

@pytest.fixture
def future_empty_competition():
competitions = loadCompetitions('tests/test_dataset.json')
return competitions[2]

@pytest.fixture
def past_competition():
competitions = loadCompetitions('tests/test_dataset.json')
return competitions[0]
return competitions[0]

@pytest.fixture
def zero_point_club():
clubs = loadClubs('tests/test_dataset.json')
return [club for club in clubs if club['points'] == 0][0]

@pytest.fixture
def hundred_point_club():
clubs = loadClubs('tests/test_dataset.json')
return [club for club in clubs if club['points'] == 100][0]
17 changes: 16 additions & 1 deletion tests/test_dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
"name":"Test Club",
"email":"test@test.fr",
"points":"11"
},
{
"name":"Zero point Club",
"email":"zero@mail.fr",
"points":"0"
},
{
"name":"Hundred points Club",
"email":"hundred@mail.fr",
"points":"100"
}
],
"competitions": [
Expand All @@ -16,6 +26,11 @@
"name": "Future Competition",
"date": "2030-03-27 10:00:00",
"numberOfPlaces": "8"
}
},
{
"name": "Future Empty Competition",
"date": "2030-03-27 10:00:00",
"numberOfPlaces": "100"
}
]
}
25 changes: 25 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime as dt
from server import MAX_PER_CLUB

class TestAuth:

Expand Down Expand Up @@ -43,4 +44,28 @@ def test_shouldnt_access_booking_page_past_competitions(self, client, test_club,
assert response.status_code == 400
assert b'Cannot book past competitions.' in response.data

def test_not_enough_points_to_book(self, client, test_club, future_competition):
places = int(test_club['points']) +1
response = client.post('/purchasePlaces', data={"competition": future_competition["name"], "club": test_club['name'], "places": places})
assert response.status_code == 200
error_message = f"Cannot book - trying to book more than what you have."
assert error_message in response.data.decode()

def test_shouldnt_book_more_than_remaining(self, client, test_club, future_competition):
places = int(future_competition['numberOfPlaces']) +1
response = client.post('/purchasePlaces', data={"competition": future_competition["name"], "club": test_club['name'], "places": places})
assert response.status_code == 200
error_message = "Cannot book - trying to book more than what remains."
assert error_message in response.data.decode()

def test_shouldnt_book_more_than_max_per_club(self, client, hundred_point_club, future_empty_competition):
places = MAX_PER_CLUB+1
response = client.post('/purchasePlaces', data={"competition": future_empty_competition["name"], "club": hundred_point_club['name'], "places": places})
assert response.status_code == 200
error_message = f'Cannot book - Trying to book more than maximum allowed'
assert error_message in response.data.decode('utf-8')

def test_shouldnt_book_when_0_points(self, client, zero_point_club):
response = client.post('/showSummary', data={"email": zero_point_club["email"]})
assert b'cannot make any reservation!' in response.data
assert b'Book places' not in response.data

0 comments on commit c0caa41

Please sign in to comment.