From 0c86fa19a545fe58e036424f2e7c551f9f0ef81c Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Tue, 2 Jun 2020 14:29:10 +0200 Subject: [PATCH] add: some test cleanup and test for non existing motion --- motion.py | 2 ++ tests/test_motion.py | 84 ++++++++++++++++++++------------------------ 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/motion.py b/motion.py index ef98529..df5db15 100644 --- a/motion.py +++ b/motion.py @@ -225,6 +225,8 @@ def show_motion(motion): + "LEFT JOIN voter canceler ON canceler.id = motion.canceled_by " + "WHERE motion.identifier=$1 AND motion.host=$3") rv = p(motion, g.voter, request.host) + if len(rv) == 0: + return "Error, Not found", 404 votes = None if may("audit", rv[0].get("type")) and not rv[0].get("running") and not rv[0].get("canceled"): votes = get_db().prepare("SELECT vote.result, voter.email FROM vote INNER JOIN voter ON voter.id = vote.voter_id WHERE vote.motion_id=$1")(rv[0].get("id")); diff --git a/tests/test_motion.py b/tests/test_motion.py index 6ec2e1b..bb4acf0 100644 --- a/tests/test_motion.py +++ b/tests/test_motion.py @@ -8,11 +8,23 @@ from datetime import datetime app.config.update( DEBUGUSER = {}, GROUP_PREFIX = {'127.0.0.1:5000': {'group1': 'g1', 'group2': 'g2'}}, - DURATION = {'127.0.0.1:5000':[3, 7, 14]} + DURATION = {'127.0.0.1:5000':[3, 7, 14]}, + SERVER_NAME = '127.0.0.1:5000' ) +app.config['TESTING'] = True +app.config['DEBUG'] = False + + class BasicTest(TestCase): + def init_test(self): + self.app = app.test_client() + self.assertEqual(app.debug, False) + + # reset database + self.db_clear() + # functions to manipulate motions def createVote(self, user, motion, vote): return self.app.post( @@ -55,32 +67,22 @@ class BasicTest(TestCase): # no specific rights required class GeneralTests(BasicTest): - + def setUp(self): - app.config['TESTING'] = True - app.config['DEBUG'] = False - app.config.update(SERVER_NAME="127.0.0.1:5000") + self.init_test() global user user = 'testuser/' - # reset database - self.db_clear() self.db_sampledata() - self.app = app.test_client() - self.assertEqual(app.debug, False) - def tearDown(self): pass def test_main_page(self): response = self.app.get('/', environ_base={'USER_ROLES': user}, follow_redirects=True) self.assertEqual(response.status_code, 200) - + def test_basic_results_data(self): result = self.app.get('/', environ_base={'USER_ROLES': user}, follow_redirects=True) - - #self.assertIn(str.encode('User: testuser'), result.data) - testtext= '
\n
'\ + '\n Motion C (Canceled)\n group1'\ + '\n
# g1.20200402.003
'\ @@ -121,7 +123,7 @@ class GeneralTests(BasicTest): self.assertIn(str.encode(testtext), result.data) testtext= 'id=\"motion-1\">' self.assertIn(str.encode(testtext), result.data) - + def test_basic_results_data_details(self): motion='g1.20200402.002' result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) @@ -149,27 +151,28 @@ class GeneralTests(BasicTest): testtext= 'id=\"motion-3\">' self.assertIn(str.encode(testtext), result.data) + def test_basic_results_data_details_not_given(self): + motion='g1.30190402.001' + result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) + self.assertEqual(result.status_code, 404) + self.assertIn(str.encode('Error, Not found'), result.data) + + class VoterTests(BasicTest): + def setUp(self): - app.config['TESTING'] = True - app.config['DEBUG'] = False - app.config.update(SERVER_NAME="127.0.0.1:5000") + self.init_test() global user user='testuser/vote:*' - # reset database - self.db_clear() self.db_sampledata() - self.app = app.test_client() - self.assertEqual(app.debug, False) - def tearDown(self): pass def test_main_page(self): response = self.app.get('/', environ_base={'USER_ROLES': user}, follow_redirects=True) self.assertEqual(response.status_code, 200) - + def test_home_data(self): result = self.app.get('/', environ_base={'USER_ROLES': user}) self.assertNotIn("