]> WPIA git - motion.git/blobdiff - tests/test_motion.py
Merge branch 'vote-button' into 'master'
[motion.git] / tests / test_motion.py
index 6ec2e1bef57e068585ada4f9d0c89005bc1c96a6..c1f996c3312966439f5bb4a5572cd5637372d350 100644 (file)
@@ -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,35 +67,27 @@ 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= '<div class="motion card" id="motion-3">\n  <div class="motion-title card-heading alert-warning">'\
             + '\n    <span class=\"title-text\">Motion C</span> (Canceled)\n    <span class=\"motion-type\">group1</span>'\
-            + '\n    <div># <a href=\"/motion/g1.20200402.003\" class=\"anchor\">g1.20200402.003</a></div>'\
+            + '\n    <div># g1.20200402.003'\
+            + '\n    <a class="btn btn-primary" href="/motion/g1.20200402.003" role="button">Result</a>'\
+            + '\n    </div>'\
             + '\n    <div class=\"date\">\n      <div>Proposed: 2020-04-02 21:47:24 (UTC) by User A</div>'\
             + '\n      <div>Canceled: 2020-04-03 21:48:24 (UTC) by User A</div></div>\n  </div>'\
             + '\n  <div class=\"card-body\">\n    <p><p>A third motion</p></p>'\
@@ -94,7 +98,9 @@ class GeneralTests(BasicTest):
         self.assertIn(str.encode(testtext), result.data)
         testtext= '<div class="motion card" id="motion-2">\n  <div class="motion-title card-heading alert-danger">'\
             + '\n    <span class=\"title-text\">Motion B</span> (Finished)\n    <span class=\"motion-type\">group1</span>'\
-            + '\n    <div># <a href=\"/motion/g1.20200402.002\" class=\"anchor\">g1.20200402.002</a></div>'\
+            + '\n    <div># g1.20200402.002'\
+            + '\n    <a class="btn btn-primary" href="/motion/g1.20200402.002" role="button">Result</a>'\
+            + '\n    </div>'\
             + '\n    <div class=\"date\">\n      <div>Proposed: 2020-04-02 21:41:26 (UTC) by User A</div>'\
             + '\n      <div>Votes until: 2020-04-04 21:41:26 (UTC)</div></div>\n  </div>'\
             + '\n  <div class=\"card-body\">\n    <p><p>A second motion</p></p>'\
@@ -104,7 +110,9 @@ class GeneralTests(BasicTest):
         self.assertIn(str.encode(testtext), result.data)
         testtext= '<div class=\"motion card\" id=\"motion-1\">\n  <div class=\"motion-title card-heading alert-success\">'\
             + '\n    <span class=\"title-text\">Motion A</span> (Finished)\n    <span class=\"motion-type\">group1</span>'\
-            + '\n    <div># <a href=\"/motion/g1.20200402.001\" class=\"anchor\">g1.20200402.001</a></div>'\
+            + '\n    <div># g1.20200402.001'\
+            + '\n    <a class="btn btn-primary" href="/motion/g1.20200402.001" role="button">Result</a>'\
+            + '\n    </div>'\
             + '\n    <div class=\"date">\n      <div>Proposed: 2020-04-02 21:40:33 (UTC) by User A</div>'\
             + '\n      <div>Votes until: 2020-04-02 21:40:33 (UTC)</div></div>\n  </div>'\
             + '\n  <div class=\"card-body\">\n    <p><p>My special motion</p></p>'\
@@ -121,7 +129,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 +157,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("<select class=\"float form-control\" name=\"category\">", str(result.data) )
@@ -235,7 +244,7 @@ class VoterTests(BasicTest):
         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)
-        
+
     def test_vote_group(self):
         motion='g1.20200402.004'
         response = self.createVote(user, motion, 'yes')
@@ -269,7 +278,7 @@ class VoterTests(BasicTest):
         response = self.createVote(user, motion, 'abstain')
         self.assertEqual(response.status_code, 500)
         self.assertIn(str.encode('Error, motion deadline has passed'), response.data)
-        
+
     def test_vote_not_given(self):
         motion='g1.30190402.001'
         response = self.createVote(user, motion, 'abstain')
@@ -298,20 +307,15 @@ class VoterTests(BasicTest):
         self.assertEqual(response.status_code, 403)
         self.assertIn(str.encode('Forbidden'), response.data)
 
+
 class CreateMotionTests(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:* create:* cancel:*'
-        # reset database
         self.db_clear()
 
-        self.app = app.test_client()
-        self.assertEqual(app.debug, False)
-    # executed after each test
     def tearDown(self):
         pass
 
@@ -335,6 +339,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='<a class=\"btn btn-primary" href=\"/motion/g1.'+datetime.today().strftime('%Y%m%d')+'.001\" role=\"button\">Vote</a>'
+        self.assertIn(str.encode(testtext), result.data)
 
         title='My Motion1'
         content='My body1'
@@ -344,7 +350,7 @@ 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')+'.002'), result.data)
-        
+
         title='My Motion2'
         content='My body2'
         response = self.createMotion(user, title, content, '3', 'group2')
@@ -434,19 +440,17 @@ class CreateMotionTests(BasicTest):
         self.assertEqual(response.status_code, 404)
         self.assertIn(str.encode('Error, Not found'), response.data)
 
+
 class AuditMotionTests(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/audit:*'
-        # reset database
-        self.db_clear()
         self.db_sampledata()
 
-        self.app = app.test_client()
-        self.assertEqual(app.debug, False)
+    def tearDown(self):
+        pass
 
     def test_see_old_vote(self):
         motion='g1.20200402.002'
@@ -456,10 +460,6 @@ class AuditMotionTests(BasicTest):
             + '\n    <div>User C: no</div>\n  </div>\n</div>\n<a href="/?start=2#motion-2" class="btn btn-primary">Back</a>'
         self.assertIn(str.encode(testtext), result.data)
 
-    # executed after each test
-    def tearDown(self):
-        pass
-
 
 if __name__ == "__main__":
     unittest.main()