4 from unittest import TestCase
6 from datetime import datetime
10 GROUP_PREFIX = {'127.0.0.1:5000': {'group1': 'g1', 'group2': 'g2'}},
11 DURATION = {'127.0.0.1:5000':[3, 7, 14]},
12 SERVER_NAME = '127.0.0.1:5000',
13 DEFAULT_HOST = '127.0.0.1:5000',
17 app.config['TESTING'] = True
18 app.config['DEBUG'] = False
20 class BasicTest(TestCase):
23 self.app = app.test_client()
24 self.assertEqual(app.debug, False)
29 # functions to manipulate motions
30 def createVote(self, user, motion, vote, voter):
32 '/motion/' + motion + '/vote/' + str(voter),
33 environ_base={'USER_ROLES': user},
37 def createMotion(self, user, motiontitle, motioncontent, days, category):
40 environ_base={'USER_ROLES': user},
41 data=dict(title=motiontitle, content=motioncontent, days=days, category=category)
44 def cancelMotion(self, user, motion, reason):
46 '/motion/' + motion +'/cancel',
47 environ_base={'USER_ROLES': user},
48 data=dict(reason=reason)
51 def finishMotion(self, user, motion):
53 '/motion/' + motion +'/finish',
54 environ_base={'USER_ROLES': user}
57 def addProxy(self, user, voter, proxy):
60 environ_base={'USER_ROLES': user},
61 data=dict(voter=voter, proxy=proxy)
64 def revokeProxy(self, user, id):
67 environ_base={'USER_ROLES': user},
71 def buildResultText(self, motiontext, yes, no, abstain):
72 return '<p>'+motiontext+'</p></p>\n <p>\nYes <span class=\"badge badge-pill badge-secondary\">'+str(yes)+'</span><br>'\
73 + '\nNo <span class=\"badge badge-pill badge-secondary\">'+str(no)+'</span><br>'\
74 + '\nAbstain <span class=\"badge badge-pill badge-secondary\">'+str(abstain)+'</span>'
78 return postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD"))
80 # functions to clear database
82 with self.open_DB() as db:
83 with app.open_resource('sql/schema.sql', mode='r') as f:
86 def db_sampledata(self):
87 with self.open_DB() as db:
88 with app.open_resource('sql/sample_data.sql', mode='r') as f: