8 Commits

Author SHA1 Message Date
9e3e049535 template fixed, 2 tests on display 2025-07-09 12:30:10 +02:00
811c635a47 Merge branch 'QA' of github.com:ylxdre/OCR-P11-Testing into feature/issue7
branch created earlier : retrieve base code
2025-07-09 11:54:08 +02:00
db692a068e Merge pull request #8 from ylxdre/bug/issue6
Bug/issue6
2025-07-08 16:58:04 +02:00
772048a6ed removed print 2025-07-08 16:56:15 +02:00
81ca8765a2 fixed indentation error 2025-07-08 16:54:58 +02:00
99b1c00200 added docstring and comments 2025-07-08 16:18:43 +02:00
c26fee3fbd made test more simple 2025-07-07 15:49:13 +02:00
2dc85f19e7 added public list of club`s points 2025-06-26 15:11:13 +02:00
6 changed files with 110 additions and 21 deletions

View File

@@ -57,16 +57,20 @@ 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'])
# check if that's the first book, and update session
if competition['name'] in session:
places = {competition['name']: session[competition['name']] + placesRequired}
else:
places = {competition['name']: placesRequired}
points = int(club['points'])
# prevent to book more than 12 places
if placesRequired <= 12:
if places[competition['name']] <= 12:
# prevent to book more than available points
if placesRequired <= points:
competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired
club['points'] = int(club['points']) - placesRequired
# set the session if that's the first book for this competition
if not competition['name'] in session:
session[competition['name']] = placesRequired
flash(f"Great ! {placesRequired} places booked for {competition['name']}")
@@ -80,11 +84,11 @@ def purchasePlaces():
competitions=competitions, now=now)
# 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)

View File

@@ -22,5 +22,6 @@
<input type="email" name="email" id=""/>
<button type="submit">Enter</button>
</form>
<a href="{{ url_for('displayPoints') }}">Board of points</a>
</body>
</html>

19
templates/points.html Normal file
View File

@@ -0,0 +1,19 @@
<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>
</li>
{% endfor %}
</ul>
<a href="{{ url_for('index') }}"> Back </a>
</body>
</html>

24
tests/test_board.py Normal file
View File

@@ -0,0 +1,24 @@
from bs4 import BeautifulSoup
from server import loadClubs
class TestBoardDisplayPoints:
def test_should_get_200(self, client):
'''
test if the page is retrieved
'''
response = client.get('/points')
assert response.status_code == 200
def test_should_display_right_size_list(self, client):
'''
test if the list of club displayed and in DB have the same size
'''
list_club = loadClubs()
response = client.get('/points')
soup = BeautifulSoup(response.data, "html.parser")
li = soup.find_all("li")
assert len(li) == len(list_club)

View File

@@ -3,49 +3,78 @@ from flask import session
class TestPoints:
def test_should_nok_when_too_much_points(self, client, connect, club1):
'''
testing both case, book with and without enough points
'''
def test_should_nok_when_too_much_points(self, client, connect, club2):
'''
test booking an amount of places greater than the available points
'''
points = int(connect.span.text)
club1.update({"places": points+1})
response = client.post('/purchasePlaces', data=club1)
club2.update({"places": points+1})
response = client.post('/purchasePlaces', data=club2)
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):
def test_should_ok_when_enough_points(self, client, connect, club2):
'''
test booking with enough points
'''
points = int(connect.span.text)
club1.update({"places": points-1})
response = client.post('/purchasePlaces', data=club1)
# One remaining point after that :
club2.update({"places": points-1})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert f"Great ! "+str(points-1)+" places booked for "+club1['competition'] == soup.li.text
assert f"Great ! "+str(points-1)+" places booked for "+club2['competition'] == soup.li.text
class TestPlaces:
'''
test the booking limit of 12 places
'''
def test_should_refuse_more_12_once(self, client, club1):
club1.update({"places": 13})
response = client.post('/purchasePlaces', data=club1)
def test_should_refuse_more_12_once(self, client, club2):
'''
test to book more than 12 places in one shot
'''
club2.update({"places": 13})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert "You can't book more than 12 places" == soup.li.text
def test_should_refuse_more_12_total(self, client, club1):
club1.update({"places": 2})
response = client.post('/purchasePlaces', data=club1)
def test_should_refuse_more_12_total(self, client, club2):
'''
test to book more than 12 places in a two-part reservation
'''
club2.update({"places": 1})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert "Great ! 2 places booked for "+club1['competition'] == soup.li.text
club1.update({"places": 12})
response = client.post('/purchasePlaces', data=club1)
assert "Great ! 1 places booked for "+club2['competition'] == soup.li.text
club2.update({"places": 12})
response = client.post('/purchasePlaces', data=club2)
soup = BeautifulSoup(response.data, "html.parser")
assert "You already booked 12 places for "+club1['competition'] == soup.li.text
assert "You already booked 12 places for "+club2['competition'] == soup.li.text
class TestDate:
'''
test the booking for the past competitions
'''
def test_should_not_display_book_link_for_past_competitions(self, connect):
'''
test that the booking link isn't displayed when competition date is older than today
'''
li = connect.find_all("li")
assert not li[0].a
assert li[1].a
def test_forged_url_on_past_competition_should_raise_flash(self, client):
'''
test that a flash warning occur when trying to connect to an URL on an old competition
'''
url = '/book/Spring Festival/Iron Temple'
response = client.get(url)
assert "You cannot book for a past competition" in response.data.decode()

12
tests/test_update.py Normal file
View File

@@ -0,0 +1,12 @@
class TestPointsUpdate:
def test_should_not_be_ok_the_second_time(self, connect, client, club2):
'''
this books an amount of points-1 places
then test if 1 points remains displayed on page
'''
points = int(connect.span.text)
club2.update({"places": points-1})
response = client.post('/purchasePlaces', data=club2)
assert f"Great ! {points-1} places booked for {club2['competition']}" in response.data.decode()