From 3f69464daef37059d23affdd4f104398cc552a39 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:19:04 +0200 Subject: [PATCH 1/2] 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 2/2] 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)