Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattgris6 committed Nov 17, 2022
1 parent b08e69f commit 5f2330a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
7 changes: 6 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from flask import Flask,render_template,request,redirect,flash,url_for

from datetime import datetime

def loadClubs():
with open('clubs.json') as c:
Expand Down Expand Up @@ -59,12 +60,16 @@ def purchasePlaces():
club = [c for c in clubs if c['name'] == request.form['club']][0]
placesRequired = int(request.form['places'])
alreadyBooked = controle_club[club['name']][competition['name']]
current_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Check date of competition
if competition['date'] < current_date:
flash('This competition is in the past!')
return render_template('welcome.html', club=club, competitions=competitions)
# Checks if club has enough points
if placesRequired > int(club["points"]):
flash(f'You do not have enough points.')
return render_template('booking.html',club=club,competition=competition)
# Checks if place booked > 12
print(alreadyBooked)
placesBooked = placesRequired + alreadyBooked
if placesBooked > MAX_PLACES:
flash(f"""You can not purchase more than 12 places per competition,
Expand Down
31 changes: 13 additions & 18 deletions templates/welcome.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Summary | GUDLFT Registration</title>
</head>
<body>
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a>

{% with messages = get_flashed_messages()%}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
<body>
<h2>Welcome, {{club['email']}} </h2><a href="{{url_for('logout')}}">Logout</a> {% with messages = get_flashed_messages()%} {% if messages %}
<ul>
{% for message in messages %}
<li>{{message}}</li>
{% endfor %}
</ul>
{% endif%}
Points available: {{club['points']}}
</ul>
{% endif%} Points available: {{club['points']}}
<h3>Competitions:</h3>
<ul>
{% for comp in competitions%}
<li>
{{comp['name']}}<br />
Date: {{comp['date']}}</br>
Number of Places: {{comp['numberOfPlaces']}}
{%if comp['numberOfPlaces']|int >0%}
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
{%endif%}
{{comp['name']}}<br /> Date: {{comp['date']}}</br>
Number of Places: {{comp['numberOfPlaces']}} {%if comp['numberOfPlaces']|int >0%}
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a> {%endif%}
</li>
<hr />
{% endfor %}
<hr /> {% endfor %}
</ul>
{%endwith%}

</body>

</html>
19 changes: 17 additions & 2 deletions tests/unit/test_purchase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest

import datetime
import server

@pytest.fixture
Expand All @@ -13,7 +13,9 @@ def club():

@pytest.fixture
def competition():
return server.competitions[0]
my_compet = server.competitions[0]
my_compet['date'] = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S")
return my_compet

class TestPurchase:
def test_purchase_too_many_places(self, client, club, competition):
Expand Down Expand Up @@ -71,3 +73,16 @@ def test_purchase_more_than_max_places_in_multiple_times(self, client, club, com
data = response.data.decode()
assert data.find("You can not purchase more than 12 places per competition") != -1
assert data.find("How many places?") != -1

def test_purchase_past_competition(self, client, club, competition):
club["points"] = 4
competition["numberOfPlaces"] = 25
competition["date"] = (datetime.datetime.now() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d %H:%M:%S")
response = client.post(
"/purchasePlaces",
data={'places':4, 'club':club["name"], 'competition':competition["name"]},
follow_redirects=True
)
assert response.status_code == 200
data = response.data.decode()
assert data.find("This competition is in the past") != -1

0 comments on commit 5f2330a

Please sign in to comment.