Compare commits
7 Commits
bug/issue1
...
691392988f
| Author | SHA1 | Date | |
|---|---|---|---|
| 691392988f | |||
| 524c4ca028 | |||
| f323cd8310 | |||
| e6d4d05917 | |||
| 5102e366e8 | |||
| b70f80f3cb | |||
| 2317006de9 |
27
server.py
27
server.py
@@ -1,5 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
from flask import Flask,render_template,request,redirect,flash,url_for
|
from flask import Flask,render_template,request,redirect,flash,url_for,session
|
||||||
|
|
||||||
|
|
||||||
def loadClubs():
|
def loadClubs():
|
||||||
@@ -29,7 +29,7 @@ def showSummary():
|
|||||||
club = [club for club in clubs if club['email'] == request.form['email']]
|
club = [club for club in clubs if club['email'] == request.form['email']]
|
||||||
if club:
|
if club:
|
||||||
return render_template('welcome.html', club=club[0], competitions=competitions)
|
return render_template('welcome.html', club=club[0], competitions=competitions)
|
||||||
flash("The email isn't found")
|
flash("Sorry, that email wasn't found")
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
@app.route('/book/<competition>/<club>')
|
@app.route('/book/<competition>/<club>')
|
||||||
@@ -48,10 +48,26 @@ def purchasePlaces():
|
|||||||
competition = [c for c in competitions if c['name'] == request.form['competition']][0]
|
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]
|
club = [c for c in clubs if c['name'] == request.form['club']][0]
|
||||||
placesRequired = int(request.form['places'])
|
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
|
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
|
||||||
|
if not competition['name'] in session:
|
||||||
|
session[competition['name']] = placesRequired
|
||||||
flash('Great-booking complete!')
|
flash('Great-booking complete!')
|
||||||
return render_template('welcome.html', club=club, competitions=competitions)
|
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)
|
||||||
|
|
||||||
# TODO: Add route for points display
|
# TODO: Add route for points display
|
||||||
|
|
||||||
@@ -59,3 +75,6 @@ def purchasePlaces():
|
|||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
if (__name__ == "__main__"):
|
||||||
|
app.run(debug=True)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif%}
|
{% endif%}
|
||||||
Points available: {{club['points']}}
|
<b id="points">Points available: </b><span>{{club['points']}}</span>
|
||||||
<h3>Competitions:</h3>
|
<h3>Competitions:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for comp in competitions%}
|
{% for comp in competitions%}
|
||||||
|
|||||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
30
tests/conftest.py
Normal file
30
tests/conftest.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import pytest
|
||||||
|
from server import app
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
EMAIL1 = "admin@irontemple.com"
|
||||||
|
EMAIL2 = "john@simplylift.co"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def club1():
|
||||||
|
data = {"competition": "Spring Festival", "club": "Iron Temple"}
|
||||||
|
return data
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def club2():
|
||||||
|
data = {"competition": "Fall Classic", "club": "Iron Temple"}
|
||||||
|
return data
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def client():
|
||||||
|
with app.test_client() as client:
|
||||||
|
yield client
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def connect(client):
|
||||||
|
response = client.post('/showSummary', data={"email": EMAIL1})
|
||||||
|
soup = BeautifulSoup(response.data, 'html.parser')
|
||||||
|
return soup
|
||||||
|
|
||||||
26
tests/test_connection.py
Normal file
26
tests/test_connection.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
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})
|
||||||
|
print(session)
|
||||||
|
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})
|
||||||
|
print(session)
|
||||||
|
soup = BeautifulSoup(response.data, 'html.parser')
|
||||||
|
assert soup.h2.text == "Welcome, "+email
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
28
tests/test_purchase.py
Normal file
28
tests/test_purchase.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from flask import session
|
||||||
|
|
||||||
|
|
||||||
|
class TestPoints:
|
||||||
|
|
||||||
|
def test_should_nok_when_too_much_points(self, client, connect, club1):
|
||||||
|
points = int(connect.span.text)
|
||||||
|
club1.update({"places": points+1})
|
||||||
|
response = client.post('/purchasePlaces', data=club1)
|
||||||
|
soup = BeautifulSoup(response.data, "html.parser")
|
||||||
|
assert "You don't have enough points" == soup.li.text
|
||||||
|
|
||||||
|
def test_should_ok_when_enough_points(self, client, connect, club1):
|
||||||
|
points = int(connect.span.text)
|
||||||
|
club1.update({"places": points-1})
|
||||||
|
response = client.post('/purchasePlaces', data=club1)
|
||||||
|
soup = BeautifulSoup(response.data, "html.parser")
|
||||||
|
assert "Great-booking complete!" == soup.li.text
|
||||||
|
|
||||||
|
|
||||||
|
class TestPlaces:
|
||||||
|
|
||||||
|
def test_should_refuse_more_than_12(self, client, club1):
|
||||||
|
club1.update({"places": 13})
|
||||||
|
response = client.post('/purchasePlaces', data=club1)
|
||||||
|
soup = BeautifulSoup(response.data, "html.parser")
|
||||||
|
assert "You can't book more than 12 places" == soup.li.text
|
||||||
Reference in New Issue
Block a user