From 5393af007f9e26f9c673d27af7d0256da7832e65 Mon Sep 17 00:00:00 2001 From: zionhigt Date: Sun, 27 Mar 2022 14:48:22 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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())