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
21 class BasicTest(TestCase):
24 self.app = app.test_client()
25 self.assertEqual(app.debug, False)
30 # functions to manipulate motions
31 def createVote(self, user, motion, vote, voter):
33 '/motion/' + motion + '/vote/' + str(voter),
34 environ_base={'USER_ROLES': user},
38 def createMotion(self, user, motiontitle, motioncontent, days, category):
41 environ_base={'USER_ROLES': user},
42 data=dict(title=motiontitle, content=motioncontent, days=days, category=category)
45 def cancelMotion(self, user, motion, reason):
47 '/motion/' + motion +'/cancel',
48 environ_base={'USER_ROLES': user},
49 data=dict(reason=reason)
52 def finishMotion(self, user, motion):
54 '/motion/' + motion +'/finish',
55 environ_base={'USER_ROLES': user}
58 def addProxy(self, user, voter, proxy):
61 environ_base={'USER_ROLES': user},
62 data=dict(voter=voter, proxy=proxy)
65 def revokeProxy(self, user, id):
68 environ_base={'USER_ROLES': user},
72 def buildResultText(self, motiontext, yes, no, abstain):
73 return '<p>'+motiontext+'</p></p>\n <p>\nYes <span class=\"badge badge-pill badge-secondary\">'+str(yes)+'</span><br>'\
74 + '\nNo <span class=\"badge badge-pill badge-secondary\">'+str(no)+'</span><br>'\
75 + '\nAbstain <span class=\"badge badge-pill badge-secondary\">'+str(abstain)+'</span>'
79 return postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD"))
81 # functions to clear database
83 with self.open_DB() as db:
84 with app.open_resource('sql/schema.sql', mode='r') as f:
87 def db_sampledata(self):
88 with self.open_DB() as db:
89 with app.open_resource('sql/sample_data.sql', mode='r') as f: