From 3a7b7050b1471f464b94713fd13757c24e7d013a Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 11:47:02 +0200 Subject: [PATCH 01/17] INIT test env --- .gitignore | 4 +++- server.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2cba99d87..1007cb110 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ lib .Python tests/ .envrc -__pycache__ \ No newline at end of file +__pycache__ +launch_flask.bat +launch_test.bat \ No newline at end of file diff --git a/server.py b/server.py index 4084baeac..4b700ef78 100644 --- a/server.py +++ b/server.py @@ -2,14 +2,14 @@ from flask import Flask,render_template,request,redirect,flash,url_for -def loadClubs(): - with open('clubs.json') as c: +def loadClubs(path='clubs.json'): + with open(path) as c: listOfClubs = json.load(c)['clubs'] return listOfClubs -def loadCompetitions(): - with open('competitions.json') as comps: +def loadCompetitions(path='competitions.json'): + with open(path) as comps: listOfCompetitions = json.load(comps)['competitions'] return listOfCompetitions From ef79a0dd0506335ba119ed6ec433023a198bb9ff Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 11:56:49 +0200 Subject: [PATCH 02/17] prepare branch name --- branchName.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 branchName.txt diff --git a/branchName.txt b/branchName.txt new file mode 100644 index 000000000..8475737c2 --- /dev/null +++ b/branchName.txt @@ -0,0 +1,12 @@ +#6 +FEATURE/Implement-Points-Display-Board +#5 +BUG/Point-updates-are-not-reflected +#4 +BUG/Booking-places-in-past-competitions +#3 +BUG/Clubs-shouldn-t-be-able-to-book-more-than-12-places-per-competition +#2 +BUG/Clubs-should-not-be-able-to-use-more-than-their-points-allowed +#1 +ERROR/Entering-a-unknown-email-crashes-the-app \ No newline at end of file From c259388cb608ace0e9cc7865e53c22793184cff7 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 12:36:45 +0200 Subject: [PATCH 03/17] includes tests --- .gitignore | 1 - tests/__init__.py | 0 tests/unit_test/__init__.py | 0 tests/unit_test/conftest.py | 32 +++++++++++++++++++ tests/unit_test/mocks_files/fixture_load.json | 16 ++++++++++ tests/unit_test/test_server.py | 20 ++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/__init__.py create mode 100644 tests/unit_test/__init__.py create mode 100644 tests/unit_test/conftest.py create mode 100644 tests/unit_test/mocks_files/fixture_load.json create mode 100644 tests/unit_test/test_server.py diff --git a/.gitignore b/.gitignore index 1007cb110..8b4d1421a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ bin include lib .Python -tests/ .envrc __pycache__ launch_flask.bat diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit_test/__init__.py b/tests/unit_test/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py new file mode 100644 index 000000000..82868db79 --- /dev/null +++ b/tests/unit_test/conftest.py @@ -0,0 +1,32 @@ +import pytest + +from server import app + +@pytest.fixture(scope="class") +def client(request): + with app.test_client() as client: + request.cls.client = client + + +@pytest.fixture(scope="class") +def clubs(request): + fixture = [ + { + "name":"TEST_CLUB", + "email":"TEST_CLUB_EMAIL", + "points":"13" + } + ] + request.cls.clubs = fixture + + +@pytest.fixture(scope="class") +def competitions(request): + fixture = [ + { + "name": "TEST_COMPETITION", + "date": "2020-03-27 10:00:00", + "numberOfPlaces": "25" + } + ] + request.cls.competitions = fixture \ No newline at end of file diff --git a/tests/unit_test/mocks_files/fixture_load.json b/tests/unit_test/mocks_files/fixture_load.json new file mode 100644 index 000000000..1d724612b --- /dev/null +++ b/tests/unit_test/mocks_files/fixture_load.json @@ -0,0 +1,16 @@ +{ + "clubs":[ + { + "name":"TEST_CLUB", + "email":"TEST_CLUB_EMAIL", + "points":"13" + } + ], + "competitions": [ + { + "name": "TEST_COMPETITION", + "date": "2020-03-27 10:00:00", + "numberOfPlaces": "25" + } + ] +} \ No newline at end of file diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py new file mode 100644 index 000000000..88cb00ebb --- /dev/null +++ b/tests/unit_test/test_server.py @@ -0,0 +1,20 @@ +from unittest.mock import patch +from unittest import TestCase + +from pytest import mark + +from server import loadClubs, loadCompetitions + + +@mark.usefixtures('client', 'clubs', 'competitions') +class TestServer(TestCase): + + def test_loadClubs(self): + self.assertListEqual(loadClubs("./tests/unit_test/mocks_files/fixture_load.json"), self.clubs) + + def test_loadCompetitions(self): + self.assertListEqual(loadCompetitions("./tests/unit_test/mocks_files/fixture_load.json"), self.competitions) + + def test_sould_login_in_out(self): + response = self.client.get("/logout") + self.assertEqual(response.status_code, 302) From 7490430a7c4811ac4f9b344c1aea1962168afe6a Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 13:21:46 +0200 Subject: [PATCH 04/17] Test for issue #1 --- tests/unit_test/conftest.py | 39 +++++++++++++++++++++------------- tests/unit_test/test_server.py | 10 ++++++++- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index 82868db79..7bd2cb951 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -1,32 +1,41 @@ import pytest +from unittest.mock import patch -from server import app - -@pytest.fixture(scope="class") -def client(request): - with app.test_client() as client: - request.cls.client = client +import server -@pytest.fixture(scope="class") -def clubs(request): - fixture = [ +def get_clubs(): + return [ { "name":"TEST_CLUB", "email":"TEST_CLUB_EMAIL", "points":"13" } ] - request.cls.clubs = fixture - -@pytest.fixture(scope="class") -def competitions(request): - fixture = [ +def get_competitions(): + return [ { "name": "TEST_COMPETITION", "date": "2020-03-27 10:00:00", "numberOfPlaces": "25" } ] - request.cls.competitions = fixture \ No newline at end of file + +@pytest.fixture(scope="class") +def clubs(request): + request.cls.clubs = get_clubs() + yield + +@pytest.fixture(scope="class") +def competitions(request): + request.cls.competitions = get_competitions() + yield + +@pytest.fixture(scope="class") +def client(request): + with patch("server.clubs", get_clubs()): + with patch("server.competitions", get_competitions()): + with server.app.test_client() as client: + request.cls.client = client + yield \ No newline at end of file diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index 88cb00ebb..ef2c372fa 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -1,4 +1,3 @@ -from unittest.mock import patch from unittest import TestCase from pytest import mark @@ -18,3 +17,12 @@ def test_loadCompetitions(self): def test_sould_login_in_out(self): response = self.client.get("/logout") self.assertEqual(response.status_code, 302) + + def test_sould_connect_with_email_exists(self): + for cl in self.clubs: + response = self.client.post("/showSummary", data={'email': cl.get('email')}) + self.assertEqual(response.status_code, 200) + + def test_sould_no_connect_with_email_does_not_exists(self): + response = self.client.post("/showSummary", data={'email': "not_exists_email@test.com"}) + assert response.status_code == 401 From b58a9a81f70564b89ec7b9d45ab67d5791e4eaae Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 13:24:11 +0200 Subject: [PATCH 05/17] Fix for issue #1 --- server.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 4b700ef78..90525ff87 100644 --- a/server.py +++ b/server.py @@ -26,8 +26,10 @@ def index(): @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) + club = [club for club in clubs if club['email'] == request.form['email']] + if len(club): + return render_template('welcome.html',club=club[0],competitions=competitions), 200 + return render_template('index.html'), 401 @app.route('/book//') From f11f07331847d6e2817ddd922e62c2e77ae7c938 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 13:31:12 +0200 Subject: [PATCH 06/17] Test for issue #2 --- tests/unit_test/test_server.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index ef2c372fa..23c50c046 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -25,4 +25,15 @@ def test_sould_connect_with_email_exists(self): def test_sould_no_connect_with_email_does_not_exists(self): response = self.client.post("/showSummary", data={'email': "not_exists_email@test.com"}) - assert response.status_code == 401 + self.assertEqual(response.status_code, 401) + + def test_sould_not_purshase_more_than_I_own(self): + for com in self.competitions: + for cl in self.clubs: + mock = { + "club": cl.get('name'), + "competition": com.get('name'), + "places": int(cl.get('points')) + 1 + } + response = self.client.post('/purchasePlaces', data=mock) + self.assertEqual(response.status_code, 403) From 06847ede7491ffe86ad6ef94953206fb2ab1e4df Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:11:43 +0200 Subject: [PATCH 07/17] Stronger test for issue #2 --- server.py | 7 ++++++- tests/unit_test/conftest.py | 2 +- tests/unit_test/test_server.py | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index 90525ff87..0e21b7c48 100644 --- a/server.py +++ b/server.py @@ -47,10 +47,15 @@ def book(competition,club): 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 placesRequired > int(club.get("points")): + flash('You haven\'t enough of points to purshase this!') + return render_template('welcome.html', club=club, competitions=competitions), 403 + competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired flash('Great-booking complete!') - return render_template('welcome.html', club=club, competitions=competitions) + return render_template('welcome.html', club=club, competitions=competitions), 200 # TODO: Add route for points display diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index 7bd2cb951..c66721c19 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -1,9 +1,9 @@ import pytest from unittest.mock import patch - import server + def get_clubs(): return [ { diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index 23c50c046..97fe9e0c6 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -35,5 +35,7 @@ def test_sould_not_purshase_more_than_I_own(self): "competition": com.get('name'), "places": int(cl.get('points')) + 1 } + response = self.client.post('/purchasePlaces', data=mock) + self.assertIn("You haven't enough of points to purshase this!", response.data.decode()) self.assertEqual(response.status_code, 403) From 3f69464daef37059d23affdd4f104398cc552a39 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:19:04 +0200 Subject: [PATCH 08/17] TESTS for issue #3 --- tests/unit_test/test_server.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index 97fe9e0c6..be1c6c5c1 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -39,3 +39,12 @@ def test_sould_not_purshase_more_than_I_own(self): response = self.client.post('/purchasePlaces', data=mock) self.assertIn("You haven't enough of points to purshase this!", response.data.decode()) self.assertEqual(response.status_code, 403) + + def test_sould_not_purshase_more_than_12_places(self): + response = self.client.post('/purchasePlaces', data={ + "club": "TEST_CLUB", + "competition": "TEST_COMPETITION", + "places": 13 + }) + self.assertIn("You cannot required more than 12 places!", response.data.decode()) + self.assertEqual(response.status_code, 403) From fbca741152161d217a711ad94e2634287eed105b Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:26:01 +0200 Subject: [PATCH 09/17] FIX issue #3 --- server.py | 4 ++++ tests/unit_test/conftest.py | 2 +- tests/unit_test/mocks_files/fixture_load.json | 2 +- tests/unit_test/test_server.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 0e21b7c48..fbab634cd 100644 --- a/server.py +++ b/server.py @@ -49,6 +49,10 @@ def purchasePlaces(): club = [c for c in clubs if c['name'] == request.form['club']][0] placesRequired = int(request.form['places']) + if placesRequired > 12: + flash('You cannot required more than 12 places!') + return render_template('welcome.html', club=club, competitions=competitions), 403 + if placesRequired > int(club.get("points")): flash('You haven\'t enough of points to purshase this!') return render_template('welcome.html', club=club, competitions=competitions), 403 diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index c66721c19..0f1f5ca7c 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -9,7 +9,7 @@ def get_clubs(): { "name":"TEST_CLUB", "email":"TEST_CLUB_EMAIL", - "points":"13" + "points":"10" } ] diff --git a/tests/unit_test/mocks_files/fixture_load.json b/tests/unit_test/mocks_files/fixture_load.json index 1d724612b..b6f88b6a8 100644 --- a/tests/unit_test/mocks_files/fixture_load.json +++ b/tests/unit_test/mocks_files/fixture_load.json @@ -3,7 +3,7 @@ { "name":"TEST_CLUB", "email":"TEST_CLUB_EMAIL", - "points":"13" + "points":"10" } ], "competitions": [ diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index be1c6c5c1..ceae4e522 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -35,7 +35,7 @@ def test_sould_not_purshase_more_than_I_own(self): "competition": com.get('name'), "places": int(cl.get('points')) + 1 } - + response = self.client.post('/purchasePlaces', data=mock) self.assertIn("You haven't enough of points to purshase this!", response.data.decode()) self.assertEqual(response.status_code, 403) From 5393af007f9e26f9c673d27af7d0256da7832e65 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:48:22 +0200 Subject: [PATCH 10/17] TESTS issue #4 --- tests/unit_test/conftest.py | 7 ++++++- tests/unit_test/mocks_files/fixture_load.json | 7 ++++++- tests/unit_test/test_server.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index 0f1f5ca7c..4246bdc06 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -16,9 +16,14 @@ def get_clubs(): def get_competitions(): return [ { - "name": "TEST_COMPETITION", + "name": "TEST_COMPETITION_1", "date": "2020-03-27 10:00:00", "numberOfPlaces": "25" + }, + { + "name": "TEST_COMPETITION_2", + "date": "2025-03-27 10:00:00", + "numberOfPlaces": "25" } ] diff --git a/tests/unit_test/mocks_files/fixture_load.json b/tests/unit_test/mocks_files/fixture_load.json index b6f88b6a8..68779f1e9 100644 --- a/tests/unit_test/mocks_files/fixture_load.json +++ b/tests/unit_test/mocks_files/fixture_load.json @@ -8,9 +8,14 @@ ], "competitions": [ { - "name": "TEST_COMPETITION", + "name": "TEST_COMPETITION_1", "date": "2020-03-27 10:00:00", "numberOfPlaces": "25" + }, + { + "name": "TEST_COMPETITION_2", + "date": "2025-03-27 10:00:00", + "numberOfPlaces": "25" } ] } \ No newline at end of file diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index ceae4e522..595356891 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -34,8 +34,7 @@ def test_sould_not_purshase_more_than_I_own(self): "club": cl.get('name'), "competition": com.get('name'), "places": int(cl.get('points')) + 1 - } - + } response = self.client.post('/purchasePlaces', data=mock) self.assertIn("You haven't enough of points to purshase this!", response.data.decode()) self.assertEqual(response.status_code, 403) @@ -43,8 +42,16 @@ def test_sould_not_purshase_more_than_I_own(self): def test_sould_not_purshase_more_than_12_places(self): response = self.client.post('/purchasePlaces', data={ "club": "TEST_CLUB", - "competition": "TEST_COMPETITION", + "competition": "TEST_COMPETITION_2", "places": 13 }) self.assertIn("You cannot required more than 12 places!", response.data.decode()) self.assertEqual(response.status_code, 403) + + def test_sould_not_purshase_booking_if_date_passed(self): + response = self.client.post('/purchasePlaces', data={ + "club": "TEST_CLUB", + "competition": "TEST_COMPETITION_2", + "places": 1 + }) + self.assertEqual(response.status_code, 403) From 1f0281360acb8f524e2cbcf3870e94cf3a2d5be3 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:50:40 +0200 Subject: [PATCH 11/17] IMPROVE TESTS issue #4 --- tests/unit_test/test_server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index 595356891..ce9f6901a 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -54,4 +54,5 @@ def test_sould_not_purshase_booking_if_date_passed(self): "competition": "TEST_COMPETITION_2", "places": 1 }) + self.assertIn("Unable to require places for already been passed competion !", response.data.decode()) self.assertEqual(response.status_code, 403) From d36ff3b03817b3a5b5ee6d4f7fa2a6ab7e80166f Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:50:58 +0200 Subject: [PATCH 12/17] FIX issue #4 --- server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index fbab634cd..80c6c19c1 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,6 @@ import json from flask import Flask,render_template,request,redirect,flash,url_for +from datetime import datetime def loadClubs(path='clubs.json'): @@ -48,11 +49,16 @@ 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] + competition_date = datetime.fromisoformat(competition.get("date")); + if competition_date < datetime.now(): + flash('Unable to require places for already been passed competion !') + return render_template('welcome.html', club=club, competitions=competitions), 403 + placesRequired = int(request.form['places']) if placesRequired > 12: flash('You cannot required more than 12 places!') return render_template('welcome.html', club=club, competitions=competitions), 403 - + if placesRequired > int(club.get("points")): flash('You haven\'t enough of points to purshase this!') return render_template('welcome.html', club=club, competitions=competitions), 403 From 60d2dcc77be7f807d1a8ca0967f0398b8162b48b Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:54:20 +0200 Subject: [PATCH 13/17] fix older tests brocken --- tests/unit_test/test_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index ce9f6901a..5b3787327 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -32,7 +32,7 @@ def test_sould_not_purshase_more_than_I_own(self): for cl in self.clubs: mock = { "club": cl.get('name'), - "competition": com.get('name'), + "competition": "TEST_COMPETITION_2", "places": int(cl.get('points')) + 1 } response = self.client.post('/purchasePlaces', data=mock) From 20fd2804296f19d0980542e27b9b92029df1c0d9 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:55:44 +0200 Subject: [PATCH 14/17] fix bad args --- tests/unit_test/test_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index 5b3787327..d958ff9a4 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -51,7 +51,7 @@ def test_sould_not_purshase_more_than_12_places(self): def test_sould_not_purshase_booking_if_date_passed(self): response = self.client.post('/purchasePlaces', data={ "club": "TEST_CLUB", - "competition": "TEST_COMPETITION_2", + "competition": "TEST_COMPETITION_1", "places": 1 }) self.assertIn("Unable to require places for already been passed competion !", response.data.decode()) From 749c49fe3c0bf13a50840020483958c44b50d751 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 15:27:04 +0200 Subject: [PATCH 15/17] TESTS issue # 5 --- tests/unit_test/conftest.py | 2 +- tests/unit_test/test_server.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index 4246bdc06..83c31c06c 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -34,7 +34,7 @@ def clubs(request): @pytest.fixture(scope="class") def competitions(request): - request.cls.competitions = get_competitions() + request.cls.competitions = get_competitions() yield @pytest.fixture(scope="class") diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index d958ff9a4..1d4742345 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -56,3 +56,13 @@ def test_sould_not_purshase_booking_if_date_passed(self): }) self.assertIn("Unable to require places for already been passed competion !", response.data.decode()) self.assertEqual(response.status_code, 403) + + def test_club_points_should_be_reflected_after_booking(self): + club = self.clubs[0] + points = int(club.get("points")) + self.client.post('/purchasePlaces', data={ + "club": club.get("name"), + "competition": "TEST_COMPETITION_2", + "places": 1 + }) + self.assertEqual(int(club.get('points')), points - 1) From 629e21e587b49e07649ac9c372ac353d9919fa6a Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 15:35:00 +0200 Subject: [PATCH 16/17] TESTS 2 issue # 5 --- server.py | 3 ++- tests/unit_test/test_server.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index 80c6c19c1..f752ef234 100644 --- a/server.py +++ b/server.py @@ -63,7 +63,8 @@ def purchasePlaces(): flash('You haven\'t enough of points to purshase this!') return render_template('welcome.html', club=club, competitions=competitions), 403 - competition['numberOfPlaces'] = int(competition['numberOfPlaces'])-placesRequired + competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired + club['points'] = int(club['points']) - placesRequired flash('Great-booking complete!') return render_template('welcome.html', club=club, competitions=competitions), 200 diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index 1d4742345..a71cd4871 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -58,11 +58,15 @@ def test_sould_not_purshase_booking_if_date_passed(self): self.assertEqual(response.status_code, 403) def test_club_points_should_be_reflected_after_booking(self): + places = 1 club = self.clubs[0] + competition = self.competitions[1] points = int(club.get("points")) + number_of_places = int(competition.get("numberOfPlaces")) self.client.post('/purchasePlaces', data={ "club": club.get("name"), - "competition": "TEST_COMPETITION_2", - "places": 1 + "competition": competition.get("name"), + "places": places }) - self.assertEqual(int(club.get('points')), points - 1) + self.assertEqual(int(club.get('points')), points - places) + self.assertEqual(int(competition.get('numberOfPlaces')), number_of_places - places) From e2f3588631f2313939d581da64a20527482f561b Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 17:10:13 +0200 Subject: [PATCH 17/17] FIX issue # 5 --- server.py | 4 ++-- tests/unit_test/conftest.py | 16 +++++++--------- tests/unit_test/mocks_files/fixture_load.json | 4 ++-- tests/unit_test/test_server.py | 5 ++--- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/server.py b/server.py index f752ef234..f3c87274b 100644 --- a/server.py +++ b/server.py @@ -63,8 +63,8 @@ def purchasePlaces(): flash('You haven\'t enough of points to purshase this!') return render_template('welcome.html', club=club, competitions=competitions), 403 - competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired - club['points'] = int(club['points']) - placesRequired + competition['numberOfPlaces'] = str(int(competition['numberOfPlaces']) - placesRequired) + club['points'] = str(int(club['points']) - placesRequired) flash('Great-booking complete!') return render_template('welcome.html', club=club, competitions=competitions), 200 diff --git a/tests/unit_test/conftest.py b/tests/unit_test/conftest.py index 83c31c06c..468cc2a6f 100644 --- a/tests/unit_test/conftest.py +++ b/tests/unit_test/conftest.py @@ -3,9 +3,7 @@ import server - -def get_clubs(): - return [ +clubs_obj = [ { "name":"TEST_CLUB", "email":"TEST_CLUB_EMAIL", @@ -13,8 +11,7 @@ def get_clubs(): } ] -def get_competitions(): - return [ +competitions_obj = [ { "name": "TEST_COMPETITION_1", "date": "2020-03-27 10:00:00", @@ -27,20 +24,21 @@ def get_competitions(): } ] + @pytest.fixture(scope="class") def clubs(request): - request.cls.clubs = get_clubs() + request.cls.clubs = clubs_obj yield @pytest.fixture(scope="class") def competitions(request): - request.cls.competitions = get_competitions() + request.cls.competitions = competitions_obj yield @pytest.fixture(scope="class") def client(request): - with patch("server.clubs", get_clubs()): - with patch("server.competitions", get_competitions()): + with patch("server.clubs", clubs_obj): + with patch("server.competitions", competitions_obj): with server.app.test_client() as client: request.cls.client = client yield \ No newline at end of file diff --git a/tests/unit_test/mocks_files/fixture_load.json b/tests/unit_test/mocks_files/fixture_load.json index 68779f1e9..d915ac3d6 100644 --- a/tests/unit_test/mocks_files/fixture_load.json +++ b/tests/unit_test/mocks_files/fixture_load.json @@ -3,7 +3,7 @@ { "name":"TEST_CLUB", "email":"TEST_CLUB_EMAIL", - "points":"10" + "points":"9" } ], "competitions": [ @@ -15,7 +15,7 @@ { "name": "TEST_COMPETITION_2", "date": "2025-03-27 10:00:00", - "numberOfPlaces": "25" + "numberOfPlaces": "24" } ] } \ No newline at end of file diff --git a/tests/unit_test/test_server.py b/tests/unit_test/test_server.py index a71cd4871..05d55f326 100644 --- a/tests/unit_test/test_server.py +++ b/tests/unit_test/test_server.py @@ -7,7 +7,6 @@ @mark.usefixtures('client', 'clubs', 'competitions') class TestServer(TestCase): - def test_loadClubs(self): self.assertListEqual(loadClubs("./tests/unit_test/mocks_files/fixture_load.json"), self.clubs) @@ -60,10 +59,10 @@ def test_sould_not_purshase_booking_if_date_passed(self): def test_club_points_should_be_reflected_after_booking(self): places = 1 club = self.clubs[0] - competition = self.competitions[1] points = int(club.get("points")) + competition = self.competitions[1] number_of_places = int(competition.get("numberOfPlaces")) - self.client.post('/purchasePlaces', data={ + response = self.client.post('/purchasePlaces', data={ "club": club.get("name"), "competition": competition.get("name"), "places": places