From 88143e52a40466ef0d5a19aed2db5c109a07426f Mon Sep 17 00:00:00 2001 From: Julien Denizot Date: Wed, 6 Nov 2024 15:28:24 +0100 Subject: [PATCH 1/2] Add public points display on index page and welcome page --- .gitignore | 3 +- server.py | 6 ++-- templates/_points_table.html | 14 +++++++++ templates/index.html | 4 ++- templates/welcome.html | 57 +++++++++++++++++++----------------- 5 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 templates/_points_table.html diff --git a/.gitignore b/.gitignore index 2cba99d87..e2d7aa6dc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ lib .Python tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +pyvenv.cfg diff --git a/server.py b/server.py index 4084baeac..2f5c86720 100644 --- a/server.py +++ b/server.py @@ -22,12 +22,12 @@ def loadCompetitions(): @app.route('/') def index(): - return render_template('index.html') + return render_template('index.html', clubs=clubs) @app.route('/showSummary',methods=['POST']) def showSummary(): club = [club for club in clubs if club['email'] == request.form['email']][0] - return render_template('welcome.html',club=club,competitions=competitions) + return render_template('welcome.html',club=club,competitions=competitions, clubs=clubs) @app.route('/book//') @@ -56,4 +56,4 @@ def purchasePlaces(): @app.route('/logout') def logout(): - return redirect(url_for('index')) \ No newline at end of file + return redirect(url_for('index')) diff --git a/templates/_points_table.html b/templates/_points_table.html new file mode 100644 index 000000000..4e4240747 --- /dev/null +++ b/templates/_points_table.html @@ -0,0 +1,14 @@ + +

Clubs Points Board

+ + + + + + {% for club in clubs %} + + + + + {% endfor %} +
Club NamePoints
{{ club['name'] }}{{ club['points'] }}
diff --git a/templates/index.html b/templates/index.html index 926526b7d..275a04489 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,5 +12,7 @@

Welcome to the GUDLFT Registration Portal!

+ + {% include '_points_table.html' %} - \ No newline at end of file + diff --git a/templates/welcome.html b/templates/welcome.html index ff6b261a2..5b6dde9ba 100644 --- a/templates/welcome.html +++ b/templates/welcome.html @@ -1,36 +1,39 @@ - - - Summary | GUDLFT Registration + + + Summary | GUDLFT Registration -

Welcome, {{club['email']}}

Logout +

Welcome, {{club['email']}}

+ Logout - {% with messages = get_flashed_messages()%} + {% include '_points_table.html' %} + + {% with messages = get_flashed_messages() %} {% if messages %} -
    - {% for message in messages %} -
  • {{message}}
  • - {% endfor %} -
- {% endif%} - Points available: {{club['points']}} -

Competitions:

-
    - {% for comp in competitions%} -
  • - {{comp['name']}}
    - Date: {{comp['date']}}
    - Number of Places: {{comp['numberOfPlaces']}} - {%if comp['numberOfPlaces']|int >0%} - Book Places - {%endif%} -
  • -
    +
      + {% for message in messages %} +
    • {{message}}
    • {% endfor %} -
    - {%endwith%} +
+ {% endif %} + {% endwith %} + Points available: {{club['points']}} +

Competitions:

+
    + {% for comp in competitions %} +
  • + {{comp['name']}}
    + Date: {{comp['date']}}
    + Number of Places: {{comp['numberOfPlaces']}} + {% if comp['numberOfPlaces']|int > 0 %} + Book Places + {% endif %} +
  • +
    + {% endfor %} +
- \ No newline at end of file + From d0dd0a8f09a9b849d72f6052f48043d50900fef7 Mon Sep 17 00:00:00 2001 From: Julien Denizot Date: Wed, 13 Nov 2024 10:20:50 +0100 Subject: [PATCH 2/2] Add test for points display board feature --- tests/unit/test_points_display.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/unit/test_points_display.py diff --git a/tests/unit/test_points_display.py b/tests/unit/test_points_display.py new file mode 100644 index 000000000..8f5fda4f4 --- /dev/null +++ b/tests/unit/test_points_display.py @@ -0,0 +1,37 @@ +import sys +import os +import pytest +sys.path.insert( + 0, os.path.abspath( + os.path.join(os.path.dirname(__file__), '../../') + ) +) + +from server import app, clubs, competitions # noqa + + +@pytest.fixture +def client(): + app.config['TESTING'] = True + with app.test_client() as client: + yield client + + +def test_points_display_on_index(client): + response = client.get('/') + assert response.status_code == 200 + + for club in clubs: + assert bytes(club['name'], 'utf-8') in response.data + assert bytes(club['points'], 'utf-8') in response.data + + +def test_points_display_after_login(client): + response = client.post( + '/showSummary', data={'email': 'john@simplylift.co'} + ) + assert response.status_code == 200 + + for club in clubs: + assert bytes(club['name'], 'utf-8') in response.data + assert bytes(club['points'], 'utf-8') in response.data