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',
+ DEFAULT_HOST = '127.0.0.1:5000',
MAX_PROXY=2
)
app.config['TESTING'] = True
app.config['DEBUG'] = False
-
class BasicTest(TestCase):
def init_test(self):
environ_base={'USER_ROLES': user},
data=dict(vote=vote)
)
-
def createMotion(self, user, motiontitle, motioncontent, days, category):
return self.app.post(
+ '\nNo <span class=\"badge badge-pill badge-secondary\">'+str(no)+'</span><br>'\
+ '\nAbstain <span class=\"badge badge-pill badge-secondary\">'+str(abstain)+'</span>'
+ # functions handling or using database
+ def open_DB(self):
+ return postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD"))
+
+ def db_select(self, sql, parameter):
+ with self.open_DB() as db:
+ rv = db.prepare(sql)(parameter)
+ return rv
+
+ def db_select2(self, sql, parameter, parameter2):
+ with self.open_DB() as db:
+ rv = db.prepare(sql)(parameter, parameter2)
+ return rv
+
+ def recordCountLog(self, parameter):
+ return self.recordCount("SELECT * FROM adminlog WHERE action=$1", parameter)
+
+ def recordCount(self, sql, parameter):
+ rv = self.db_select(sql, parameter)
+ return len(rv)
+
+ def logRecordDetailsTest(self, parameter, recordno, voterid, comment, actionuserid):
+ rv = self.db_select("SELECT * FROM adminlog WHERE action=$1 ORDER BY id", parameter)
+ self.assertEqual(voterid, rv[recordno].get("user_id"))
+ if comment:
+ self.assertEqual(comment, rv[recordno].get("comment"))
+ else:
+ self.assertEqual('', rv[recordno].get("comment"))
+ self.assertEqual(actionuserid, rv[recordno].get("action_user_id"))
+
# 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 self.open_DB() 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 self.open_DB() as db:
with app.open_resource('sql/sample_data.sql', mode='r') as f:
db.execute(f.read())