Skip to content
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ lib
.Python
tests/
.envrc
__pycache__
__pycache__
.env
.vscode/
env/
12 changes: 12 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from server import app


@pytest.fixture
def client():
# active le mode test de Flask
app.config["TESTING"] = True
# crée un faux navigateur
with app.test_client() as client:
# donne ce navigateur aux tests
yield client
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning
25 changes: 19 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def loadCompetitions():
listOfCompetitions = json.load(comps)['competitions']
return listOfCompetitions


a = 1
app = Flask(__name__)
app.secret_key = 'something_special'

Expand All @@ -26,8 +26,15 @@ def index():

@app.route('/showSummary',methods=['POST'])
def showSummary():
club = [club for club in clubs if club['email'] == request.form['email']][0]
return render_template('welcome.html',club=club,competitions=competitions)
club = [club for club in clubs if club['email'] == request.form['email']]

if not club:
flash("Sorry, that email was not found")
return redirect(url_for("index"))

return render_template('welcome.html',
club=club[0],
competitions=competitions)


@app.route('/book/<competition>/<club>')
Expand All @@ -46,9 +53,15 @@ def purchasePlaces():
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places'])
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
flash('Great-booking complete!')
return render_template('welcome.html', club=club, competitions=competitions)

point_club = int(club['points'])
if point_club < placesRequired:
flash('You are not authorized to book this number of places!')
return render_template('welcome.html', club=club, competitions=competitions)
else:
flash('Great-booking complete!')
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
return render_template('welcome.html', club=club, competitions=competitions)


# TODO: Add route for points display
Expand Down
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<body>
<h1>Welcome to the GUDLFT Registration Portal!</h1>
Please enter your secretary email to continue:

{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
{% endif %}
{% endwith %}

<form action="showSummary" method="post">
<label for="email">Email:</label>
<input type="email" name="email" id=""/>
Expand Down
5 changes: 4 additions & 1 deletion templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title>Summary | GUDLFT Registration</title>
</head>
<body>
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
<h2>Welcome, {{club['email']}}
</h2><a href="{{url_for('logout')}}">Logout</a>

{% with messages = get_flashed_messages()%}
{% if messages %}
Expand All @@ -15,7 +16,9 @@ <h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>
{% endfor %}
</ul>
{% endif%}

Points available: {{club['points']}}

<h3>Competitions:</h3>
<ul>
{% for comp in competitions%}
Expand Down
41 changes: 41 additions & 0 deletions test/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

def test_show_summary_with_valid_email(client):
response = client.post("/showSummary", data={
"email": "admin@irontemple.com"
})

assert response.status_code == 200
assert b"Welcome" in response.data

def test_show_summary_with_unknown_email(client):
response = client.post("/showSummary", data={
"email": "unknown@test.com"
}, follow_redirects=True)

assert response.status_code == 200
assert b"Sorry, that email was not found" in response.data



def test_purchase_places_with_valid_number_of_places(client):
response = client.post("/purchasePlaces", data={
"competition": "Spring Festival",
"club": "Iron Temple",
"places": "2"
}, follow_redirects=True)

assert response.status_code == 200
assert b"Great-booking complete!" in response.data

def test_purchase_places_with_too_many_places(client):
response = client.post("/purchasePlaces", data={
"competition": "Spring Festival",
"club": "Iron Temple",
"places": "5",
})

assert response.status_code == 200
assert b"You are not authorized to book this number of places" in response.data