X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Ftest_motion.py;h=0399df04fc955922eae2510351774e556135cfb6;hb=27e9c554929138818e62ae4e624dd3450a84b556;hp=6551a31ed7e516e538b83fec1f8416ecd19e98de;hpb=e59274f6a108ec57931014e8fcb1319c63fa1f2d;p=motion.git diff --git a/tests/test_motion.py b/tests/test_motion.py index 6551a31..0399df0 100644 --- a/tests/test_motion.py +++ b/tests/test_motion.py @@ -27,9 +27,9 @@ class BasicTest(TestCase): self.db_clear() # functions to manipulate motions - def createVote(self, user, motion, vote): + def createVote(self, user, motion, vote, voter): return self.app.post( - '/motion/' + motion +'/vote', + '/motion/' + motion + '/vote/' + str(voter), environ_base={'USER_ROLES': user}, data=dict(vote=vote) ) @@ -93,6 +93,8 @@ class GeneralTests(BasicTest): self.init_test() global user user = 'testuser/' + global userid + userid = 4 self.db_sampledata() def tearDown(self): @@ -105,41 +107,39 @@ class GeneralTests(BasicTest): def test_basic_results_data(self): result = self.app.get('/', environ_base={'USER_ROLES': user}, follow_redirects=True) testtext= '
\n
'\ - + '\n Motion C (Canceled)\n group1'\ + + '\n Motion C (Canceled)\n group1'\ + '\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

'\ - + '\n

\nYes 1
'\ - + '\nNo 0
'\ - + '\nAbstain 0
\n

'\ - + '\n

Cancelation reason: Entered with wrong text

\n
\n
' + + '\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
\n

A third motion

'\ + + '\n

\nYes 1
'\ + + '\nNo 0
'\ + + '\nAbstain 0
\n

'\ + + '\n

Cancelation reason: Entered with wrong text

\n
\n\n' self.assertIn(str.encode(testtext), result.data) testtext= '
\n
'\ - + '\n Motion B (Finished)\n group1'\ + + '\n Motion B (Finished)\n group1'\ + '\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

'\ - + '\n

\nYes 1
'\ - + '\nNo 2
'\ - + '\nAbstain 0
\n

\n
\n
\n' - self.assertIn(str.encode(testtext), result.data) - testtext= '
\n
'\ - + '\n Motion A (Finished)\n group1'\ + + '\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
\n

A second motion

\n

'\ + + '\nYes 1
'\ + + '\nNo 2
'\ + + '\nAbstain 0
\n

\n
\n\n' + self.assertIn(str.encode(testtext), result.data) + testtext= '
\n
'\ + + '\n Motion A (Finished)\n group1'\ + '\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

'\ - + '\n

\nYes 2
'\ - + '\nNo 1
'\ - + '\nAbstain 0
\n

\n
\n
\n' + + '\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
\n

My special motion

\n

'\ + + '\nYes 2
'\ + + '\nNo 1
'\ + + '\nAbstain 0
\n

\n
\n\n' self.assertIn(str.encode(testtext), result.data) testtext= 'Proxy management' self.assertNotIn(str.encode(testtext), result.data) @@ -161,7 +161,7 @@ class GeneralTests(BasicTest): def test_vote(self): motion='g1.20200402.004' - response = self.createVote(user, motion, 'yes') + response = self.createVote(user, motion, 'yes', userid) self.assertEqual(response.status_code, 403) self.assertIn(str.encode('Forbidden'), response.data) @@ -212,6 +212,8 @@ class VoterTests(BasicTest): self.init_test() global user user='testuser/vote:*' + global userid + userid = 4 self.db_sampledata() def tearDown(self): @@ -227,61 +229,61 @@ class VoterTests(BasicTest): def test_vote_yes(self): motion='g1.20200402.004' - response = self.createVote(user, motion, 'yes') + response = self.createVote(user, motion, 'yes', userid) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) resulttext=self.buildResultText('A fourth motion', 1, 0, 0) result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) - testtext= 'class=\"btn btn-success\" name=\"vote\" value="yes" id="vote-yes">yes' + testtext= 'class=\"btn btn-success\" name=\"vote\" value="yes" id="vote-yes">Yes' self.assertIn(str.encode(testtext), result.data) - testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">no' + testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">No' self.assertIn(str.encode(testtext), result.data) - testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">abstain' + testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">Abstain' self.assertIn(str.encode(testtext), result.data) def test_vote_no(self): motion='g1.20200402.004' - response = self.createVote(user, motion, 'no') + response = self.createVote(user, motion, 'no', userid) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) resulttext=self.buildResultText('A fourth motion', 0, 1, 0) self.assertIn(str.encode(resulttext), result.data) result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) - testtext= 'class="btn btn-primary" name="vote\" value=\"yes\" id=\"vote-yes\">yes' + testtext= 'class="btn btn-primary" name="vote\" value=\"yes\" id=\"vote-yes\">Yes' self.assertIn(str.encode(testtext), result.data) - testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"no\" id=\"vote-no\">no' + testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"no\" id=\"vote-no\">No' self.assertIn(str.encode(testtext), result.data) - testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">abstain' + testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">Abstain' self.assertIn(str.encode(testtext), result.data) def test_vote_abstain(self): motion='g1.20200402.004' - response = self.createVote(user, motion, 'abstain') + response = self.createVote(user, motion, 'abstain', userid) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) resulttext=self.buildResultText('A fourth motion', 0, 0, 1) self.assertIn(str.encode(resulttext), result.data) result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) - testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"yes\" id=\"vote-yes\">yes' + testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"yes\" id=\"vote-yes\">Yes' self.assertIn(str.encode(testtext), result.data) - testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">no' + testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">No' self.assertIn(str.encode(testtext), result.data) - testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">abstain' + testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">Abstain' self.assertIn(str.encode(testtext), result.data) def test_vote_change(self): motion='g1.20200402.004' - response = self.createVote(user, motion, 'yes') + response = self.createVote(user, motion, 'yes', userid) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) resulttext=self.buildResultText('A fourth motion', 1, 0, 0) self.assertIn(str.encode(resulttext), result.data) - response = self.createVote(user, motion, 'no') + response = self.createVote(user, motion, 'no', userid) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) resulttext=self.buildResultText('A fourth motion', 0, 1, 0) self.assertIn(str.encode(resulttext), result.data) - response = self.createVote(user, motion, 'abstain') + response = self.createVote(user, motion, 'abstain', userid) self.assertEqual(response.status_code, 302) result = self.app.get('/', environ_base={'USER_ROLES': user}) resulttext=self.buildResultText('A fourth motion', 0, 0, 1) @@ -289,41 +291,41 @@ class VoterTests(BasicTest): def test_vote_group(self): motion='g1.20200402.004' - response = self.createVote(user, motion, 'yes') + response = self.createVote(user, motion, 'yes', userid) self.assertEqual(response.status_code, 302) motion='g1.20200402.004' user1='testuser/vote:group1' - response = self.createVote(user1, motion, 'yes') + response = self.createVote(user1, motion, 'yes', userid) self.assertEqual(response.status_code, 302) motion='g1.20200402.004' user1='testuser/vote:group1 vote:group2' - response = self.createVote(user1, motion, 'yes') + response = self.createVote(user1, motion, 'yes', userid) self.assertEqual(response.status_code, 302) def test_vote_wrong_group(self): motion='g1.20200402.004' user1='testuser/vote:group2' - response = self.createVote(user1, motion, 'yes') + response = self.createVote(user1, motion, 'yes', userid) self.assertEqual(response.status_code, 403) self.assertIn(str.encode('Forbidden'), response.data) def test_vote_closed(self): motion='g1.20200402.002' - response = self.createVote(user, motion, 'abstain') + response = self.createVote(user, motion, 'abstain', userid) 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') + response = self.createVote(user, motion, 'abstain', userid) 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' - response = self.createVote(user, motion, 'abstain') + response = self.createVote(user, motion, 'abstain', userid) self.assertEqual(response.status_code, 404) self.assertIn(str.encode('Error, Not found'), response.data) @@ -343,8 +345,8 @@ class VoterTests(BasicTest): def test_see_old_vote(self): motion='g1.20200402.002' result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) - testtext= '
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

\n
\n'\ + testtext= '
Proposed: 2020-04-02 21:41:26 (UTC) by User A
\n
Votes until: 2020-04-04 21:41:26 (UTC)
'\ + + '\n \n \n
\n

A second motion

\n
\n'\ + '\nBack' self.assertIn(str.encode(testtext), result.data) @@ -718,7 +720,7 @@ class ProxyManagementTests(BasicTest): testtext= 'holds proxy of: User B\n' self.assertIn(str.encode(testtext), result.data) - response = self.revokeProxy(user, 4) + response = self.revokeProxy(user, userid) self.assertEqual(response.status_code, 302) result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True) testtext= '\n '\ @@ -763,6 +765,103 @@ class ProxyManagementTests(BasicTest): + '
\n' self.assertIn(str.encode(testtext), result.data) +class ProxyVoteTests(BasicTest): + + def setUp(self): + self.init_test() + global user + user='testuser/vote:* proxyadmin:*' + self.db_sampledata() + + def tearDown(self): + pass + + def test_proxy_vote(self): + voter='testuser' + proxy='User B' + proxyid=2 + proxyuser='User B/vote:*' + + response = self.addProxy(user, proxy, voter) + self.assertEqual(response.status_code, 302) + + motion='g1.20200402.004' + response = self.createVote(user, motion, 'yes', proxyid) + self.assertEqual(response.status_code, 302) + + # testuser view + result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) + # own vote without change + testtext= '
\n'\ + + '\n'\ + + '\n'\ + + '\n
' + self.assertIn(str.encode(testtext), result.data) + # proxy vote with change + testtext= '
\n'\ + + '\n'\ + + '\n'\ + + '\n
\n' + self.assertIn(str.encode(testtext), result.data) + + # User B view + result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': proxyuser}, follow_redirects=True) + # own vote without change + testtext= '

My vote

\nGiven by testuser\n'\ + + '
\n'\ + + '\n'\ + + '\n'\ + + '\n
' + self.assertIn(str.encode(testtext), result.data) + + # change vote + response = self.createVote(user, motion, 'no', proxyid) + self.assertEqual(response.status_code, 302) + + result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True) + testtext= '
\n'\ + + '\n'\ + + '\n'\ + + '\n
\n' + self.assertIn(str.encode(testtext), result.data) + + def test_proxy_vote_no_proxy(self): + voter='testuser' + proxy='User B' + # wrong proxy id + proxyid=3 + + response = self.addProxy(user, proxy, voter) + self.assertEqual(response.status_code, 302) + + motion='g1.20200402.004' + response = self.createVote(user, motion, 'yes', proxyid) + self.assertEqual(response.status_code, 400) + self.assertIn(str.encode('Error, proxy not found'), response.data) + + # non existing id + proxyid=10000 + + motion='g1.20200402.004' + response = self.createVote(user, motion, 'yes', proxyid) + self.assertEqual(response.status_code, 400) + self.assertIn(str.encode('Error, proxy not found'), response.data) + + def test_proxy_vote_no_voter(self): + voter='User A' + proxy='User B' + proxyid=2 + + response = self.addProxy(user, proxy, voter) + self.assertEqual(response.status_code, 302) + + user1='testuser1/' + motion='g1.20200402.004' + response = self.createVote(user1, motion, 'yes', proxyid) + self.assertEqual(response.status_code, 403) + self.assertIn(str.encode('Forbidden'), response.data) + + if __name__ == "__main__": unittest.main()