Compare commits

...

5 Commits

Author SHA1 Message Date
0370de60e0 added ok and nok on points 2025-07-03 11:41:17 +02:00
813b7849fe test Ok on soup 2025-07-02 17:27:06 +02:00
9705789809 works better with init 2025-07-02 15:07:28 +02:00
b34382c46c first try to get session cookie 2025-07-02 15:06:46 +02:00
90cae5ffc9 first try with fixture for login 2025-07-02 11:36:51 +02:00
6 changed files with 78 additions and 7 deletions

View File

@ -29,7 +29,7 @@ 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)
flash("The email isn't found")
flash("Sorry, that email wasn't found")
return redirect(url_for('index'))
@app.route('/book/<competition>/<club>')
@ -53,11 +53,10 @@ def purchasePlaces():
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
if competition['numberOfPlaces'] < 0:
competition['numberOfPlaces'] = 0
flash('Great-booking complete!')
flash("Great-booking complete!")
else:
flash("You don't have enough points")
return render_template('welcome.html', club=club,
competitions=competitions)
return render_template('welcome.html', club=club, competitions=competitions)

View File

@ -5,7 +5,7 @@
<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 %}
@ -15,7 +15,7 @@
{% endfor %}
</ul>
{% endif%}
Points available: {{club['points']}}
<b id="points">Points available: </b><span>{{club['points']}}</span>
<h3>Competitions:</h3>
<ul>
{% for comp in competitions%}
@ -33,4 +33,4 @@
{%endwith%}
</body>
</html>
</html>

0
tests/__init__.py Normal file
View File

28
tests/conftest.py Normal file
View File

@ -0,0 +1,28 @@
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

25
tests/test_connection.py Normal file
View File

@ -0,0 +1,25 @@
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

19
tests/test_purchase.py Normal file
View File

@ -0,0 +1,19 @@
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)
data = club1.update({"places": points-1})
response = client.post('/purchasePlaces', data=club1)
soup = BeautifulSoup(response.data, "html.parser")
assert "Great-booking complete!" == soup.li.text