X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Ftest_motion.py;h=1bc65858461318e377cf8660479502895cf80cff;hb=66a7e727089249cd3eeea99c2aead5fb6a9550ce;hp=fe853852d292ff3e1f7c9c0a60b297fd626f58aa;hpb=8cdf0f76acf9f0e22417cbe3ef80b784e2e975e6;p=motion.git diff --git a/tests/test_motion.py b/tests/test_motion.py index fe85385..1bc6585 100644 --- a/tests/test_motion.py +++ b/tests/test_motion.py @@ -5,8 +5,26 @@ from unittest import TestCase from motion import app 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]}, + 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( @@ -30,6 +48,12 @@ class BasicTest(TestCase): data=dict(reason=reason) ) + def finishMotion(self, user, motion): + return self.app.post( + '/motion/' + motion +'/finish', + environ_base={'USER_ROLES': user} + ) + def buildResultText(self, motiontext, yes, no, abstain): return '

'+motiontext+'

\n

\nYes '+str(yes)+'
'\ + '\nNo '+str(no)+'
'\ @@ -37,47 +61,39 @@ class BasicTest(TestCase): # functions to clear database def db_clear(self): - db = postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD")) - with app.open_resource('sql/schema.sql', mode='r') as f: - db.execute(f.read()) + with postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD")) as db: + with app.open_resource('sql/schema.sql', mode='r') as f: + db.execute(f.read()) def db_sampledata(self): - db = postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD")) - with app.open_resource('sql/sample_data.sql', mode='r') as f: - db.execute(f.read()) + with postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD")) as db: + with app.open_resource('sql/sample_data.sql', mode='r') as f: + db.execute(f.read()) # 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
'\ + + '\n
# g1.20200402.003'\ + + '\n Result'\ + + '\n
'\ + '\n
\n
Proposed: 2020-04-02 21:47:24 (UTC) by User A
'\ + '\n
Canceled: 2020-04-03 21:48:24 (UTC) by User A
\n
'\ + '\n
\n

A third motion

'\ @@ -88,7 +104,9 @@ class GeneralTests(BasicTest): self.assertIn(str.encode(testtext), result.data) testtext= '
\n
'\ + '\n Motion B (Finished)\n group1'\ - + '\n
# g1.20200402.002
'\ + + '\n
# g1.20200402.002'\ + + '\n Result'\ + + '\n
'\ + '\n
\n
Proposed: 2020-04-02 21:41:26 (UTC) by User A
'\ + '\n
Votes until: 2020-04-04 21:41:26 (UTC)
\n
'\ + '\n
\n

A second motion

'\ @@ -98,7 +116,9 @@ class GeneralTests(BasicTest): self.assertIn(str.encode(testtext), result.data) testtext= '
\n
'\ + '\n Motion A (Finished)\n group1'\ - + '\n '\ + + '\n
# g1.20200402.001'\ + + '\n Result'\ + + '\n
'\ + '\n
\n
Proposed: 2020-04-02 21:40:33 (UTC) by User A
'\ + '\n
Votes until: 2020-04-02 21:40:33 (UTC)
\n
'\ + '\n
\n

My special motion

'\ @@ -115,11 +135,11 @@ 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) - testtext= '

A second motion

\n
\n
\nBack\n' + testtext= '

A second motion

\n
\n
\nBack' self.assertIn(str.encode(testtext), result.data) def test_vote(self): @@ -143,27 +163,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("