]> WPIA git - motion.git/blobdiff - tests/test_motion.py
add: adjust user handling per host
[motion.git] / tests / test_motion.py
index 1bc65858461318e377cf8660479502895cf80cff..769deb131896a029710f670bad96e0dcdcd80cca 100644 (file)
@@ -1,75 +1,7 @@
-import motion
-import unittest
+from datetime import datetime
+from tests.test_basics import BasicTest
 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]},
-    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(
-            '/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 finishMotion(self, user, motion):
-        return self.app.post(
-            '/motion/' + motion +'/finish',
-            environ_base={'USER_ROLES': user}
-        )
-
-    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())
-
 
 # no specific rights required
 class GeneralTests(BasicTest):
@@ -78,6 +10,8 @@ class GeneralTests(BasicTest):
         self.init_test()
         global user
         user = 'testuser/'
+        global userid
+        userid = 4
         self.db_sampledata()
 
     def tearDown(self):
@@ -90,42 +24,42 @@ class GeneralTests(BasicTest):
     def test_basic_results_data(self):
         result = self.app.get('/', environ_base={'USER_ROLES': user}, follow_redirects=True)
         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    <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></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    </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    <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></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>\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># 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>'\
-            + '\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>'
+            + '\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))
@@ -144,7 +78,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)
 
@@ -169,13 +103,34 @@ class GeneralTests(BasicTest):
         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):
         self.init_test()
         global user
         user='testuser/vote:*'
+        global userid
+        userid = 4
         self.db_sampledata()
 
     def tearDown(self):
@@ -191,61 +146,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</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)
@@ -253,41 +208,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)
 
@@ -307,8 +262,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= '<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)
 
@@ -447,6 +402,19 @@ 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" 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" name="cancel" value="cancel" id="cancel">Cancel</button>'
+        self.assertNotIn(str.encode(testtext), result.data)
+
     def test_cancelMotion(self):
         self.db_sampledata()
 
@@ -479,6 +447,19 @@ class CreateMotionTests(BasicTest):
         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" 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" name="finish" value="finish" id="finish">Finish</button>'
+        self.assertNotIn(str.encode(testtext), result.data)
+
     def test_finishMotion(self):
         self.db_sampledata()
 
@@ -517,6 +498,360 @@ 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)
 
+class ProxyManagementTests(BasicTest):
+
+    def setUp(self):
+        self.init_test()
+        global user
+        user='testuser/proxyadmin:*'
+        global userid
+        userid=4
+        self.db_sampledata()
+
+    def tearDown(self):
+        pass
+
+    def test_see_proxy(self):
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= 'div class="container">\n<form action="/proxy/add" method="POST">'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to:'
+        self.assertNotIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of:'
+        self.assertNotIn(str.encode(testtext), result.data)
+        testtext= '<select class="float form-control" name="voter">\n        '\
+            + '<option>User A</option>\n        <option>User B</option>\n        '\
+            + '<option>User C</option>\n        '\
+            + '<option>testuser</option>\n      '\
+            + '</select>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= '<select class="float form-control" name="proxy">\n          '\
+            + '<option>User A</option>\n          '\
+            + '<option>User B</option>\n          '\
+            + '<option>User C</option>\n          '\
+            + '<option>testuser</option>\n      '\
+            + '</select>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        <th>Proxy</th>\n        <th></th>\n      </thead>\n    '\
+            + '</table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= '<a class="nav-link" href="/proxy">Proxy management</a>'
+        self.assertIn(str.encode(testtext), result.data)
+
+    def test_add_proxy(self):
+        voter=''
+        proxy=''
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, voter equals proxy.'), response.data)
+
+        voter='User A'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, proxy not found.'), response.data)
+
+        voter='User Z'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, voter not found.'), response.data)
+
+        voter=''
+        proxy='User B'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, voter not found.'), response.data)
+
+        voter='User B'
+        proxy='User B'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, voter equals proxy.'), response.data)
+        
+        voter='User A'
+        proxy='User Z'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, proxy not found.'), response.data)
+
+        voter='User A'
+        proxy='User B'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 302)
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<form action="/proxy/revoke" method="POST">'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        '\
+            + '<th>Proxy</th>\n        <th></th>\n      </thead>\n      '\
+            + '<tr>\n        <td>User A</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="1">Revoke</button></td>\n      '\
+            + '</tr>\n    </table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, proxy allready given.'), response.data)
+
+        voter='User A'
+        proxy='User C'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, proxy allready given.'), response.data)
+
+        voter='User C'
+        proxy='User B'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 302)
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        '\
+            + '<th>Proxy</th>\n        <th></th>\n      </thead>\n      '\
+            + '<tr>\n        <td>User A</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="1">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User C</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="2">Revoke</button></td>\n      '\
+            + '</tr>\n    </table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to:'
+        self.assertNotIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of:'
+        self.assertNotIn(str.encode(testtext), result.data)
+
+        voter='testuser'
+        proxy='User B'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, Max proxy for \'User B\' reached.'), response.data)
+        
+        voter='testuser'
+        proxy='User A'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 302)
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        <th>Proxy</th>\n        <th></th>\n      </thead>\n      '\
+            + '<tr>\n        <td>testuser</td>\n        <td>User A</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="3">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User A</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="1">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User C</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="2">Revoke</button></td>\n      '\
+            + '</tr>\n    </table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to: User A\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of:'
+        self.assertNotIn(str.encode(testtext), result.data)
+
+        voter='User B'
+        proxy='testuser'
+        response = self.addProxy(user, voter, proxy)
+        self.assertEqual(response.status_code, 302)
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        <th>Proxy</th>\n        <th></th>\n      </thead>\n      '\
+            + '<tr>\n        <td>testuser</td>\n        <td>User A</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="3">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User A</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="1">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User B</td>\n        <td>testuser</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="4">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User C</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="2">Revoke</button></td>\n      '\
+            + '</tr>\n    </table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to: User A\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of: User B\n'
+        self.assertIn(str.encode(testtext), result.data)
+
+        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= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        <th>Proxy</th>\n        <th></th>\n      </thead>\n      '\
+            + '<tr>\n        <td>testuser</td>\n        <td>User A</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="3">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User A</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="1">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User C</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="2">Revoke</button></td>\n      '\
+            + '</tr>\n    </table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to: User A\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of:'
+        self.assertNotIn(str.encode(testtext), result.data)
+
+        response = self.revokeProxy(user, 3)
+        self.assertEqual(response.status_code, 302)
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        <th>Proxy</th>\n        <th></th>\n      </thead>\n      '\
+            + '<tr>\n        <td>User A</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="1">Revoke</button></td>\n      </tr>\n      '\
+            + '<tr>\n        <td>User C</td>\n        <td>User B</td>\n        '\
+            + '<td><button type="submit" class="btn btn-danger" name="id" value="2">Revoke</button></td>\n      '\
+            + '</tr>\n    </table>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to:'
+        self.assertNotIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of:'
+        self.assertNotIn(str.encode(testtext), result.data)
+
+        result = self.app.post('proxy/revokeall', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        self.assertEqual(response.status_code, 302)
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= '<table>\n      '\
+            + '<thead>\n        '\
+            + '<th>Voter</th>\n        <th>Proxy</th>\n        <th></th>\n      </thead>\n'\
+            + '</table>\n'
+        self.assertNotIn(str.encode(testtext), result.data)
+
+        proxytest="proxytest"
+        with self.open_DB() as db:
+            db.prepare("INSERT INTO voter(\"email\", \"host\") VALUES($1, $2)")(proxytest, '127.0.0.1:5001')
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+
+        response = self.addProxy(user, proxytest, 'testuser')
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, voter not found.'), response.data)
+
+        response = self.addProxy(user, 'testuser', proxytest)
+        self.assertEqual(response.status_code, 400)
+        self.assertIn(str.encode('Error, proxy not found.'), response.data)
+
+    def test_see_proxy_host_only(self):
+        proxytest="proxytest"
+        with self.open_DB() as db:
+            db.prepare("INSERT INTO voter(\"email\", \"host\") VALUES($1, $2)")(proxytest, '127.0.0.1:5001')
+        result = self.app.get('proxy', environ_base={'USER_ROLES': user}, follow_redirects=True)
+        testtext= 'div class="container">\n<form action="/proxy/add" method="POST">'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= 'proxy granted to:'
+        self.assertNotIn(str.encode(testtext), result.data)
+        testtext= 'holds proxy of:'
+        self.assertNotIn(str.encode(testtext), result.data)
+        testtext= '<select class="float form-control" name="voter">\n        '\
+            + '<option>User A</option>\n        <option>User B</option>\n        '\
+            + '<option>User C</option>\n        '\
+            + '<option>testuser</option>\n      '\
+            + '</select>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        testtext= '<select class="float form-control" name="proxy">\n          '\
+            + '<option>User A</option>\n          '\
+            + '<option>User B</option>\n          '\
+            + '<option>User C</option>\n          '\
+            + '<option>testuser</option>\n      '\
+            + '</select>\n'
+        self.assertIn(str.encode(testtext), result.data)
+        self.assertNotIn(str.encode(proxytest), 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= '<form action="/motion/g1.20200402.004/vote/4" method="POST">\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="yes" id="vote-yes">Yes</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="no" id="vote-no">No</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="abstain" id="vote-abstain">Abstain</button>\n</form>'
+        self.assertIn(str.encode(testtext), result.data)
+        # proxy vote with change
+        testtext= '<form action="/motion/g1.20200402.004/vote/2" method="POST">\n'\
+            + '<button type="submit" class="btn btn-success" name="vote" value="yes" id="vote-yes">Yes</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="no" id="vote-no">No</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="abstain" id="vote-abstain">Abstain</button>\n</form>\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= '<h3>My vote</h3>\nGiven by testuser\n'\
+            + '<form action="/motion/g1.20200402.004/vote/2" method="POST">\n'\
+            + '<button type="submit" class="btn btn-success" name="vote" value="yes" id="vote-yes">Yes</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="no" id="vote-no">No</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="abstain" id="vote-abstain">Abstain</button>\n</form>'
+        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= '<form action="/motion/g1.20200402.004/vote/2" method="POST">\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="yes" id="vote-yes">Yes</button>\n'\
+            + '<button type="submit" class="btn btn-success" name="vote" value="no" id="vote-no">No</button>\n'\
+            + '<button type="submit" class="btn btn-primary" name="vote" value="abstain" id="vote-abstain">Abstain</button>\n</form>\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()