Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: test booking page #5

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ def index():
@app.route('/show_summary',methods=['POST','GET'])
def show_summary():
email = request.form.get("email") if request.method == "POST" else request.args.get("email")

if not email:
flash("Email is required. Please login.", "error")
return redirect(url_for('index'))

club = next((club for club in clubs if club['email'] == email), None)

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

flash("Wrong credentials, please retry", "error")
return redirect(url_for('index')), 400
return redirect(url_for('index'))

#display the booking page
@app.route('/book/<competition>/<club>', methods=['GET', 'POST'])
Expand Down
8 changes: 8 additions & 0 deletions tests/test_booking_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

def test_booking_page_when_club_not_found(client, setup_data):
"""TEST: The booking page should load when credentials are correct"""
response = client.get('/book/Competition 5/Club D', follow_redirects=True)

assert response.status_code == 200
assert b"Something went wrong - Please try again" in response.data
6 changes: 3 additions & 3 deletions tests/test_purchase_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_purchase_places_success(client, setup_data):
assert response.status_code == 302
assert int(competitions[0]['numberOfPlaces']) == 15

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

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


def test_purchase_places_not_enough_points(client, setup_data):
def test_cant_purchase_places_not_enough_points(client, setup_data):
# TEST cant buy if not enough points
_, clubs = setup_data
response = client.post('/purchasePlaces', data={
Expand Down
7 changes: 7 additions & 0 deletions tests/test_show_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ def test_error_when_wrong_credentials(client, setup_data):

assert response.status_code == 200
assert b"Wrong credentials, please retry" in response.data

def test_error_when_no_email(client, setup_data):
"""TEST: No email inputed should redirect to index with an error message"""
response = client.post('/show_summary', data={'email': ''}, follow_redirects=True)

assert response.status_code == 200
assert b"Email is required. Please login." in response.data