Skip to content

Commit b328bdf

Browse files
authored
Merge pull request #5 from Jbguerin13/test-booking-page
feat: test booking page
2 parents 0301b3f + 88a5081 commit b328bdf

4 files changed

+24
-4
lines changed

server.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ def index():
3030
@app.route('/show_summary',methods=['POST','GET'])
3131
def show_summary():
3232
email = request.form.get("email") if request.method == "POST" else request.args.get("email")
33+
34+
if not email:
35+
flash("Email is required. Please login.", "error")
36+
return redirect(url_for('index'))
37+
3338
club = next((club for club in clubs if club['email'] == email), None)
3439

3540
if club:
3641
return render_template('welcome.html', club=club, competitions=competitions)
3742

3843
flash("Wrong credentials, please retry", "error")
39-
return redirect(url_for('index')), 400
44+
return redirect(url_for('index'))
4045

4146
#display the booking page
4247
@app.route('/book/<competition>/<club>', methods=['GET', 'POST'])

tests/test_booking_page.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
3+
def test_booking_page_when_club_not_found(client, setup_data):
4+
"""TEST: The booking page should load when credentials are correct"""
5+
response = client.get('/book/Competition 5/Club D', follow_redirects=True)
6+
7+
assert response.status_code == 200
8+
assert b"Something went wrong - Please try again" in response.data

tests/test_purchase_place.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_purchase_places_success(client, setup_data):
1212
assert response.status_code == 302
1313
assert int(competitions[0]['numberOfPlaces']) == 15
1414

15-
def test_purchase_places_not_enough_places(client, setup_data):
15+
def test_cant_purchase_places_not_enough_places(client, setup_data):
1616
#TEST cant buy if not enough places
1717
competitions, _ = setup_data
1818
response = client.post('/purchasePlaces', data={
@@ -25,7 +25,7 @@ def test_purchase_places_not_enough_places(client, setup_data):
2525
assert b"Not enough places available." in response.data
2626
assert int(competitions[1]['numberOfPlaces']) == 5
2727

28-
def test_purchase_places_more_than_12(client, setup_data):
28+
def test_cant_purchase_places_more_than_12(client, setup_data):
2929
#TEST cant buy more than 12 places
3030
competitions, _ = setup_data
3131
response = client.post('/purchasePlaces', data={
@@ -39,7 +39,7 @@ def test_purchase_places_more_than_12(client, setup_data):
3939
assert b"You cannot book more than 12 places per competition." in response.data
4040

4141

42-
def test_purchase_places_not_enough_points(client, setup_data):
42+
def test_cant_purchase_places_not_enough_points(client, setup_data):
4343
# TEST cant buy if not enough points
4444
_, clubs = setup_data
4545
response = client.post('/purchasePlaces', data={

tests/test_show_summary.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ def test_error_when_wrong_credentials(client, setup_data):
1414

1515
assert response.status_code == 200
1616
assert b"Wrong credentials, please retry" in response.data
17+
18+
def test_error_when_no_email(client, setup_data):
19+
"""TEST: No email inputed should redirect to index with an error message"""
20+
response = client.post('/show_summary', data={'email': ''}, follow_redirects=True)
21+
22+
assert response.status_code == 200
23+
assert b"Email is required. Please login." in response.data

0 commit comments

Comments
 (0)