Compare commits
2 Commits
2dc85f19e7
...
bug/issue1
| Author | SHA1 | Date | |
|---|---|---|---|
| 40226a45a6 | |||
| 1009ebfc1e |
3
Pipfile
3
Pipfile
@@ -10,6 +10,9 @@ itsdangerous = "==1.1.0"
|
||||
jinja2 = "==2.11.2"
|
||||
markupsafe = "==1.1.1"
|
||||
werkzeug = "==1.0.1"
|
||||
pytest = "*"
|
||||
pytest-flask = "*"
|
||||
bs4 = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
||||
84
Pipfile.lock
generated
84
Pipfile.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "55e68c2c6e7fb3f1685b9dfe66180ae537a367985700c08a86ccd664d56ccad7"
|
||||
"sha256": "4d7a66df30afcd7f894d943098d49a686eaad5e68b7b19762f763bcb22c05499"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@@ -17,6 +17,22 @@
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"beautifulsoup4": {
|
||||
"hashes": [
|
||||
"sha256:9bbbb14bfde9d79f38b8cd5f8c7c85f4b8f2523190ebed90e950a8dea4cb1c4b",
|
||||
"sha256:dbb3c4e1ceae6aefebdaf2423247260cd062430a410e38c66f2baa50a8437195"
|
||||
],
|
||||
"markers": "python_full_version >= '3.7.0'",
|
||||
"version": "==4.13.4"
|
||||
},
|
||||
"bs4": {
|
||||
"hashes": [
|
||||
"sha256:a48685c58f50fe127722417bae83fe6badf500d54b55f7e39ffe43b798653925",
|
||||
"sha256:abf8742c0805ef7f662dce4b51cca104cffe52b835238afc169142ab9b3fbccc"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.0.2"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
|
||||
@@ -35,6 +51,14 @@
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
|
||||
"version": "==1.1.2"
|
||||
},
|
||||
"iniconfig": {
|
||||
"hashes": [
|
||||
"sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7",
|
||||
"sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760"
|
||||
],
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==2.1.0"
|
||||
},
|
||||
"itsdangerous": {
|
||||
"hashes": [
|
||||
"sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19",
|
||||
@@ -112,6 +136,64 @@
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==1.1.1"
|
||||
},
|
||||
"packaging": {
|
||||
"hashes": [
|
||||
"sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484",
|
||||
"sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f"
|
||||
],
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==25.0"
|
||||
},
|
||||
"pluggy": {
|
||||
"hashes": [
|
||||
"sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3",
|
||||
"sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"
|
||||
],
|
||||
"markers": "python_version >= '3.9'",
|
||||
"version": "==1.6.0"
|
||||
},
|
||||
"pygments": {
|
||||
"hashes": [
|
||||
"sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887",
|
||||
"sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b"
|
||||
],
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==2.19.2"
|
||||
},
|
||||
"pytest": {
|
||||
"hashes": [
|
||||
"sha256:539c70ba6fcead8e78eebbf1115e8b589e7565830d7d006a8723f19ac8a0afb7",
|
||||
"sha256:7c67fd69174877359ed9371ec3af8a3d2b04741818c51e5e99cc1742251fa93c"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version >= '3.9'",
|
||||
"version": "==8.4.1"
|
||||
},
|
||||
"pytest-flask": {
|
||||
"hashes": [
|
||||
"sha256:58be1c97b21ba3c4d47e0a7691eb41007748506c36bf51004f78df10691fa95e",
|
||||
"sha256:c0e36e6b0fddc3b91c4362661db83fa694d1feb91fa505475be6732b5bc8c253"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==1.3.0"
|
||||
},
|
||||
"soupsieve": {
|
||||
"hashes": [
|
||||
"sha256:6e60cc5c1ffaf1cebcc12e8188320b72071e922c2e897f737cadce79ad5d30c4",
|
||||
"sha256:ad282f9b6926286d2ead4750552c8a6142bc4c783fd66b0293547c8fe6ae126a"
|
||||
],
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==2.7"
|
||||
},
|
||||
"typing-extensions": {
|
||||
"hashes": [
|
||||
"sha256:8676b788e32f02ab42d9e7c61324048ae4c6d844a399eebace3d4979d75ceef4",
|
||||
"sha256:a1514509136dd0b477638fc68d6a91497af5076466ad0fa6c338e44e359944af"
|
||||
],
|
||||
"markers": "python_version >= '3.9'",
|
||||
"version": "==4.14.0"
|
||||
},
|
||||
"werkzeug": {
|
||||
"hashes": [
|
||||
"sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
{
|
||||
"name":"Iron Temple",
|
||||
"email": "admin@irontemple.com",
|
||||
"points":"47"
|
||||
"points":"4"
|
||||
},
|
||||
{ "name":"She Lifts",
|
||||
"email": "kate@shelifts.co.uk",
|
||||
|
||||
61
server.py
61
server.py
@@ -1,6 +1,5 @@
|
||||
import json
|
||||
from flask import Flask,render_template,request,redirect,flash,url_for,session
|
||||
from datetime import datetime
|
||||
from flask import Flask,render_template,request,redirect,flash,url_for
|
||||
|
||||
|
||||
def loadClubs():
|
||||
@@ -20,8 +19,6 @@ app.secret_key = 'something_special'
|
||||
|
||||
competitions = loadCompetitions()
|
||||
clubs = loadClubs()
|
||||
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
@@ -29,26 +26,25 @@ def index():
|
||||
|
||||
@app.route('/showSummary',methods=['POST'])
|
||||
def showSummary():
|
||||
club = [club for club in clubs if club['email'] == request.form['email']]
|
||||
if club:
|
||||
return render_template('welcome.html', club=club[0], competitions=competitions, now=now)
|
||||
flash("The email isn't found")
|
||||
return redirect(url_for('index'))
|
||||
try:
|
||||
club = [club for club in clubs if club['email'] == request.form['email']][0]
|
||||
# if club:
|
||||
return render_template('welcome.html', club=club, competitions=competitions)
|
||||
# flash("Sorry, that email wasn't found")
|
||||
# return redirect(url_for('index'))
|
||||
except IndexError:
|
||||
flash("Sorry, that email wasn't found")
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/book/<competition>/<club>')
|
||||
def book(competition,club):
|
||||
foundClub = [c for c in clubs if c['name'] == club][0]
|
||||
foundCompetition = [c for c in competitions if c['name'] == competition][0]
|
||||
if foundClub and foundCompetition:
|
||||
if foundCompetition['date'] > now:
|
||||
return render_template('booking.html',club=foundClub,competition=foundCompetition)
|
||||
else:
|
||||
flash("You cannot book for a past competition")
|
||||
return render_template('welcome.html', club=foundClub,
|
||||
competitions=competitions, now=now)
|
||||
return render_template('booking.html',club=foundClub,competition=foundCompetition)
|
||||
else:
|
||||
flash("Something went wrong-please try again")
|
||||
return render_template('welcome.html', club=club, competitions=competitions, now=now)
|
||||
return render_template('welcome.html', club=club, competitions=competitions)
|
||||
|
||||
|
||||
@app.route('/purchasePlaces',methods=['POST'])
|
||||
@@ -56,37 +52,14 @@ 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'])
|
||||
if competition['name'] in session:
|
||||
places = {competition['name']: session[competition['name']] + placesRequired}
|
||||
else:
|
||||
places = {competition['name']: placesRequired}
|
||||
points = int(club['points'])
|
||||
if placesRequired <= 12:
|
||||
if places[competition['name']] <= 12:
|
||||
if placesRequired <= points:
|
||||
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
|
||||
club['points'] = int(club['points']) - placesRequired
|
||||
print(club['points'])
|
||||
if not competition['name'] in session:
|
||||
session[competition['name']] = placesRequired
|
||||
flash(f"Great ! {placesRequired} places booked for {competition['name']}")
|
||||
else:
|
||||
flash("You don't have enough points")
|
||||
else:
|
||||
flash(f"You already booked 12 places for {competition['name']}")
|
||||
else:
|
||||
flash("You can't book more than 12 places")
|
||||
return render_template('welcome.html', club=club,
|
||||
competitions=competitions, now=now)
|
||||
competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired
|
||||
flash('Great-booking complete!')
|
||||
return render_template('welcome.html', club=club, competitions=competitions)
|
||||
|
||||
|
||||
# TODO: Add route for points display
|
||||
@app.route('/points')
|
||||
def displayPoints():
|
||||
return render_template('points.html', clubs=clubs)
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
return redirect(url_for('index'))
|
||||
|
||||
if (__name__ == "__main__"):
|
||||
app.run(debug=True)
|
||||
|
||||
@@ -22,6 +22,5 @@
|
||||
<input type="email" name="email" id=""/>
|
||||
<button type="submit">Enter</button>
|
||||
</form>
|
||||
<a href="{{ url_for('displayPoints') }}">Board of points</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Board of clubs and points || GUDLFT</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Current points</h2>
|
||||
<ul>
|
||||
{% for club in clubs %}
|
||||
<li><strong>club : </strong> {{club['name']}} </br>
|
||||
<strong>Points : </strong>{{club['points']}}</br>
|
||||
</br>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<a href="{{ url_for('index') }}"> Back </a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -5,15 +5,15 @@
|
||||
<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 %}
|
||||
<ul>
|
||||
{% for message in messages %}
|
||||
{% for message in messages %}
|
||||
<li>{{message}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</ul>
|
||||
{% endif%}
|
||||
Points available: {{club['points']}}
|
||||
<h3>Competitions:</h3>
|
||||
@@ -23,7 +23,7 @@
|
||||
{{comp['name']}}<br />
|
||||
Date: {{comp['date']}}</br>
|
||||
Number of Places: {{comp['numberOfPlaces']}}
|
||||
{%if comp['numberOfPlaces']|int >0 and comp['date'] > now%}
|
||||
{%if comp['numberOfPlaces']|int >0%}
|
||||
<a href="{{ url_for('book',competition=comp['name'],club=club['name']) }}">Book Places</a>
|
||||
{%endif%}
|
||||
</li>
|
||||
@@ -33,4 +33,4 @@
|
||||
{%endwith%}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
7
tests/conftest.py
Normal file
7
tests/conftest.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import pytest
|
||||
from server import app
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with app.test_client() as client:
|
||||
yield client
|
||||
22
tests/test_connection.py
Normal file
22
tests/test_connection.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from flask import session
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def test_should_status_code_ok(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_display_sorry_with_unknown_email(client):
|
||||
email = "test@test.com"
|
||||
response = client.post('/showSummary', data={"email": email})
|
||||
assert "_flashes" in session
|
||||
assert session["_flashes"] == [("message", "Sorry, that email wasn't found")]
|
||||
|
||||
|
||||
def test_shoul_display_page_on_known_email(client):
|
||||
email = "admin@irontemple.com"
|
||||
response = client.post('/showSummary', data={"email": email})
|
||||
soup = BeautifulSoup(response.data, 'html.parser')
|
||||
assert soup.h2.text == "Welcome, "+email
|
||||
|
||||
Reference in New Issue
Block a user