X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Ftest_motion.py;h=1bc65858461318e377cf8660479502895cf80cff;hb=66a7e727089249cd3eeea99c2aead5fb6a9550ce;hp=bb4acf01ffab6970583e37101fecd655cd77c682;hpb=e459f85797c9ace2a9367294a5be7435533d3d37;p=motion.git diff --git a/tests/test_motion.py b/tests/test_motion.py index bb4acf0..1bc6585 100644 --- a/tests/test_motion.py +++ b/tests/test_motion.py @@ -48,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)+'
'\ @@ -85,7 +91,9 @@ class GeneralTests(BasicTest): result = self.app.get('/', environ_base={'USER_ROLES': user}, follow_redirects=True) 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

'\ @@ -96,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

'\ @@ -106,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

'\ @@ -127,7 +139,7 @@ class GeneralTests(BasicTest): 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): @@ -264,14 +276,14 @@ class VoterTests(BasicTest): def test_vote_closed(self): motion='g1.20200402.002' response = self.createVote(user, motion, 'abstain') - self.assertEqual(response.status_code, 500) - self.assertIn(str.encode('Error, motion deadline has passed'), response.data) + self.assertEqual(response.status_code, 403) + self.assertIn(str.encode('Error, out of time'), response.data) def test_vote_canceled(self): motion='g1.20200402.003' response = self.createVote(user, motion, 'abstain') - self.assertEqual(response.status_code, 500) - self.assertIn(str.encode('Error, motion deadline has passed'), response.data) + self.assertEqual(response.status_code, 403) + self.assertIn(str.encode('Error, motion was canceled'), response.data) def test_vote_not_given(self): motion='g1.30190402.001' @@ -286,6 +298,12 @@ class VoterTests(BasicTest): self.assertEqual(response.status_code, 403) self.assertIn(str.encode('Forbidden'), response.data) + def test_finishMotion(self): + motion='g1.20200402.004' + response = self.finishMotion(user, motion) + self.assertEqual(response.status_code, 403) + self.assertIn(str.encode('Forbidden'), response.data) + def test_see_old_vote(self): motion='g1.20200402.002' result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) @@ -307,7 +325,7 @@ class CreateMotionTests(BasicTest): def setUp(self): self.init_test() global user - user='testuser/vote:* create:* cancel:*' + user='testuser/vote:* create:* cancel:* finish:*' self.db_clear() def tearDown(self): @@ -333,6 +351,8 @@ class CreateMotionTests(BasicTest): self.assertIn(str.encode(title), result.data) self.assertIn(str.encode(content), result.data) self.assertIn(str.encode('g1.'+datetime.today().strftime('%Y%m%d')+'.001'), result.data) + testtext='Vote' + self.assertIn(str.encode(testtext), result.data) title='My Motion1' content='My body1' @@ -396,9 +416,25 @@ class CreateMotionTests(BasicTest): title='My Motion' content='My body' response = self.createMotion(user, title, content, '21', 'group1') - self.assertEqual(response.status_code, 500) + self.assertEqual(response.status_code, 400) self.assertIn(str.encode('Error, invalid length'), response.data) + def test_createMotionMissingData(self): + title='' + content='' + response = self.createMotion(user, title, content, '3', 'group1') + self.assertEqual(response.status_code, 400) + self.assertIn(str.encode('Error, missing title'), response.data) + title='New Motion' + response = self.createMotion(user, title, content, '3', 'group1') + self.assertEqual(response.status_code, 400) + self.assertIn(str.encode('Error, missing content'), response.data) + title='' + content='New Content' + response = self.createMotion(user, title, content, '3', 'group1') + self.assertEqual(response.status_code, 400) + self.assertIn(str.encode('Error, missing title'), response.data) + def test_createMotionWrongGroup(self): title='My Motion' content='My body' @@ -420,18 +456,47 @@ class CreateMotionTests(BasicTest): self.assertEqual(response.status_code, 500) self.assertIn(str.encode('Error, form requires reason'), response.data) - reason='cancel test' + reason='cancel-test' response = self.cancelMotion(user, motion, reason) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) self.assertIn(b'Cancelation reason: ' + str.encode(reason), result.data) - motion='g1.30190402.001' + motion='g1.20190402.001' reason="none" response = self.cancelMotion(user, motion, reason) self.assertEqual(response.status_code, 404) self.assertIn(str.encode('Error, Not found'), response.data) + motion='g1.30200402.001' + reason="cancel-test" + response = self.cancelMotion(user, motion, reason) + self.assertEqual(response.status_code, 404) + self.assertIn(str.encode('Error, Not found'), response.data) + + motion='g1.20200402.004' + response = self.cancelMotion(user, motion, reason) + self.assertEqual(response.status_code, 403) + self.assertIn(str.encode('Error, motion was canceled'), response.data) + + def test_finishMotion(self): + self.db_sampledata() + + motion='g1.20200402.004' + response = self.finishMotion(user, motion) + self.assertEqual(response.status_code, 302) + result = self.app.get('/', environ_base={'USER_ROLES': user}) + self.assertIn(b'Motion D (Finished)', result.data) + + motion='g1.30190402.001' + response = self.finishMotion(user, motion) + self.assertEqual(response.status_code, 404) + self.assertIn(str.encode('Error, Not found'), response.data) + + motion='g1.20200402.001' + response = self.finishMotion(user, motion) + self.assertEqual(response.status_code, 403) + self.assertIn(str.encode('Error, out of time'), response.data) class AuditMotionTests(BasicTest):