]> WPIA git - motion.git/blobdiff - tests/test_motion.py
Merge branch 'finish_move' into 'master'
[motion.git] / tests / test_motion.py
index 6ec2e1bef57e068585ada4f9d0c89005bc1c96a6..436c06f446275a35c0a1b467e7722306475c3cf8 100644 (file)
-import motion
-import unittest
-import postgresql
-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]}
-)
-
-class BasicTest(TestCase):
-
-    # functions to manipulate motions
-    def createVote(self, user, motion, vote):
-        return self.app.post(
-            '/motion/' + motion +'/vote',
-            environ_base={'USER_ROLES': user},
-            data=dict(vote=vote)
-        )
-        
-
-    def createMotion(self, user, motiontitle, motioncontent, days, category):
-        return self.app.post(
-            '/motion',
-            environ_base={'USER_ROLES': user},
-            data=dict(title=motiontitle, content=motioncontent, days=days, category=category)
-        )
-
-    def cancelMotion(self, user, motion, reason):
-        return self.app.post(
-            '/motion/' + motion +'/cancel',
-            environ_base={'USER_ROLES': user},
-            data=dict(reason=reason)
-        )
-
-    def buildResultText(self, motiontext, yes, no, abstain):
-        return '<p>'+motiontext+'</p></p>\n    <p>\nYes <span class=\"badge badge-pill badge-secondary\">'+str(yes)+'</span><br>'\
-            + '\nNo <span class=\"badge badge-pill badge-secondary\">'+str(no)+'</span><br>'\
-            + '\nAbstain <span class=\"badge badge-pill badge-secondary\">'+str(abstain)+'</span>'
-
-    # functions to clear database
-    def db_clear(self):
-        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):
-        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())
-
+from tests.test_basics import BasicTest
+from motion import app
 
 # 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()
+        global userid
+        userid = 4
         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 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>'\
-            + '\n    <p>\nYes <span class=\"badge badge-pill badge-secondary\">1</span><br>'\
-            + '\nNo <span class=\"badge badge-pill badge-secondary\">0</span><br>'\
-            + '\nAbstain <span class=\"badge badge-pill badge-secondary\">0</span><br>\n    </p>'\
-            + '\n    <p>Cancelation reason: Entered with wrong text</p>\n  </div>\n</div>'
+            + '\n    <span class="title-text">Motion C</span> (Canceled)\n    <span class="motion-type">group1</span>'\
+            + '\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>\n     </div>\n  </div>'\
+            + '\n  <div class="card-body">\n    <p><p>A third motion</p></p>'\
+            + '\n    <p>\nYes <span class="badge badge-pill badge-secondary">1</span><br>'\
+            + '\nNo <span class="badge badge-pill badge-secondary">0</span><br>'\
+            + '\nAbstain <span class="badge badge-pill badge-secondary">0</span><br>\n    </p>'\
+            + '\n    <p>Cancelation reason: Entered with wrong text</p>\n  </div>\n</div>\n'
         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 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>'\
-            + '\n    <p>\nYes <span class=\"badge badge-pill badge-secondary\">1</span><br>'\
-            + '\nNo <span class=\"badge badge-pill badge-secondary\">2</span><br>'\
-            + '\nAbstain <span class=\"badge badge-pill badge-secondary\">0</span><br>\n    </p>\n  </div>\n</div>\n'
+            + '\n    <span class="title-text">Motion B</span> (Finished)\n    <span class="motion-type">group1</span>'\
+            + '\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>\n     </div>\n  </div>'\
+            + '\n  <div class="card-body">\n    <p><p>A second motion</p></p>\n    <p>'\
+            + '\nYes <span class="badge badge-pill badge-secondary">1</span><br>'\
+            + '\nNo <span class="badge badge-pill badge-secondary">2</span><br>'\
+            + '\nAbstain <span class="badge badge-pill badge-secondary">0</span><br>\n    </p>\n  </div>\n</div>\n'
         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 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>'\
-            + '\n    <p>\nYes <span class=\"badge badge-pill badge-secondary\">2</span><br>'\
-            + '\nNo <span class=\"badge badge-pill badge-secondary\">1</span><br>'\
-            + '\nAbstain <span class=\"badge badge-pill badge-secondary\">0</span><br>\n    </p>\n  </div>\n</div>\n</div>'
+        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># 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>\n     </div>\n  </div>'\
+            + '\n  <div class="card-body">\n    <p><p>My special motion</p></p>\n    <p>'\
+            + '\nYes <span class="badge badge-pill badge-secondary">2</span><br>'\
+            + '\nNo <span class="badge badge-pill badge-secondary">1</span><br>'\
+            + '\nAbstain <span class="badge badge-pill badge-secondary">0</span><br>\n    </p>\n  </div>\n</div>\n'
         self.assertIn(str.encode(testtext), result.data)
+        testtext= 'Proxy management'
+        self.assertNotIn(str.encode(testtext), result.data)
 
         # start with second motion
         result = self.app.get('/', environ_base={'USER_ROLES': user}, query_string=dict(start=2))
@@ -121,16 +68,16 @@ 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= '<p>A second motion</p></p>\n  </div>\n</div>\n<a href=\"/?start=2#motion-2\" class=\"btn btn-primary\">Back</a>\n</body>'
+        testtext= '<p>A second motion</p></p>\n  </div>\n</div>\n<a href=\"/?start=2#motion-2\" class=\"btn btn-primary\">Back</a>'
         self.assertIn(str.encode(testtext), result.data)
 
     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)
 
@@ -149,130 +96,152 @@ 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)
+
+    def test_no_proxy(self):
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        self.assertEqual(result.status_code, 403)
+        self.assertIn(str.encode('Forbidden'), result.data)
+
+    def test_no_proxy_add(self):
+        result = self.app.post('proxy/add', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        self.assertEqual(result.status_code, 403)
+        self.assertIn(str.encode('Forbidden'), result.data)
+
+    def test_no_proxy_revoke(self):
+        result = self.app.post('proxy/revoke', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        self.assertEqual(result.status_code, 403)
+        self.assertIn(str.encode('Forbidden'), result.data)
+
+    def test_no_proxy_revokeAll(self):
+        result = self.app.post('proxy/revokeall', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        self.assertEqual(result.status_code, 403)
+        self.assertIn(str.encode('Forbidden'), 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()
+        global userid
+        userid = 4
         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) )
 
     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</button>'
+        testtext= 'class=\"btn btn-success\" name=\"vote\" value="yes" id="vote-yes">Yes</button>'
         self.assertIn(str.encode(testtext), result.data)
-        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">no</button>'
+        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">No</button>'
         self.assertIn(str.encode(testtext), result.data)
-        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">abstain</button>'
+        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">Abstain</button>'
         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</button>'
+        testtext= 'class="btn btn-primary" name="vote\" value=\"yes\" id=\"vote-yes\">Yes</button>'
         self.assertIn(str.encode(testtext), result.data)
-        testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"no\" id=\"vote-no\">no</button>'
+        testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"no\" id=\"vote-no\">No</button>'
         self.assertIn(str.encode(testtext), result.data)
-        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">abstain</button>'
+        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">Abstain</button>'
         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</button>'
+        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"yes\" id=\"vote-yes\">Yes</button>'
         self.assertIn(str.encode(testtext), result.data)
-        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">no</button>'
+        testtext= 'class=\"btn btn-primary\" name=\"vote\" value=\"no\" id=\"vote-no\">No</button>'
         self.assertIn(str.encode(testtext), result.data)
-        testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">abstain</button>'
+        testtext= 'class=\"btn btn-success\" name=\"vote\" value=\"abstain\" id=\"vote-abstain\">Abstain</button>'
         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)
         self.assertIn(str.encode(resulttext), result.data)
-        
+
     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')
-        self.assertEqual(response.status_code, 500)
-        self.assertIn(str.encode('Error, motion deadline has passed'), response.data)
+        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')
-        self.assertEqual(response.status_code, 500)
-        self.assertIn(str.encode('Error, motion deadline has passed'), response.data)
-        
+        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)
 
@@ -283,11 +252,17 @@ 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)
-        testtext= '<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>\n  </div>\n</div>'\
+        testtext= '<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>'\
+            + '\n     </div>\n  </div>\n  <div class="card-body">\n    <p><p>A second motion</p></p>\n  </div>\n</div>'\
             + '\n<a href="/?start=2#motion-2" class="btn btn-primary">Back</a>'
         self.assertIn(str.encode(testtext), result.data)
 
@@ -298,20 +273,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
+        user='testuser/vote:* create:* cancel:* finish:*'
         self.db_clear()
 
-        self.app = app.test_client()
-        self.assertEqual(app.debug, False)
-    # executed after each test
     def tearDown(self):
         pass
 
@@ -335,6 +305,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 +316,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')
@@ -398,9 +370,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'
@@ -413,6 +401,21 @@ class CreateMotionTests(BasicTest):
         self.assertEqual(response.status_code, 403)
         self.assertIn(str.encode('Forbidden'), response.data)
 
+    def test_SeeCancelMotion(self):
+        self.db_sampledata()
+
+        motion='g1.20200402.004'
+        result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<button type="submit" class="btn btn-danger btn-confirm" data-confirm="Do you really want to cancel the motion?" '\
+            + 'data-reply="Cancel,Confirm" name="cancel" value="cancel" id="cancel">Cancel</button>'
+        self.assertIn(str.encode(testtext), result.data)
+
+        motion='g1.20200402.004'
+        result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': 'testuser/vote:*'}, follow_redirects=True)
+        testtext= '<button type="submit" class="btn btn-danger btn-confirm" data-confirm="Do you really want to cancel the motion?" '\
+            + 'data-reply="Cancel,Confirm" name="cancel" value="cancel" id="cancel">Cancel</button>'
+        self.assertNotIn(str.encode(testtext), result.data)
+
     def test_cancelMotion(self):
         self.db_sampledata()
 
@@ -422,31 +425,91 @@ 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_SeeFinishMotion(self):
+        self.db_sampledata()
+
+        motion='g1.20200402.004'
+        result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<button type="submit" class="btn btn-danger btn-confirm" data-confirm="Do you really want to finish the motion?" '\
+            + 'data-reply="Cancel,Confirm" name="finish" value="finish" id="finish">Finish</button>'
+        self.assertIn(str.encode(testtext), result.data)
+
+        motion='g1.20200402.004'
+        result = self.app.get('/motion/' + motion, environ_base={'USER_ROLES': 'testuser/vote:*'}, follow_redirects=True)
+        testtext= '<button type="submit" class="btn btn-danger btn-confirm" data-confirm="Do you really want to finish the motion?" '\
+            + 'data-reply="Cancel,Confirm" name="finish" value="finish" id="finish">Finish</button>'
+        self.assertNotIn(str.encode(testtext), result.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</span> (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)
+
+    def test_createMotionWait(self):
+        # test no limit given
+        self.db_sampledata()
+        title='My Motion'
+        content='My body'
+        response = self.createMotion(user, title, content, '3', 'group1')
+        self.assertEqual(response.status_code, 302)
+
+        # test different host
+        app.config.update(MOTION_WAIT_MINUTES={'127.0.0.1:5001':1})
+        response = self.createMotion(user, title, content, '3', 'group1')
+        self.assertEqual(response.status_code, 302)
+
+        # test 3 minutes
+        app.config.update(MOTION_WAIT_MINUTES={'127.0.0.1:5000':3})
+        response = self.createMotion(user, title, content, '3', 'group1')
+        self.assertIn(str.encode('Error, time between last motion to short. The current setting is 3 minute(s).'), 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 +519,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()