X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Ftest_motion.py;h=6551a31ed7e516e538b83fec1f8416ecd19e98de;hb=e59274f6a108ec57931014e8fcb1319c63fa1f2d;hp=3fc34bd0af42c81071b91ef7f420a510442c50d0;hpb=a7b623959e195264ead5cc778aa4653dff75668f;p=motion.git diff --git a/tests/test_motion.py b/tests/test_motion.py index 3fc34bd..6551a31 100644 --- a/tests/test_motion.py +++ b/tests/test_motion.py @@ -5,8 +5,27 @@ 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', + MAX_PROXY=2 +) + +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( @@ -30,6 +49,26 @@ class BasicTest(TestCase): data=dict(reason=reason) ) + def finishMotion(self, user, motion): + return self.app.post( + '/motion/' + motion +'/finish', + environ_base={'USER_ROLES': user} + ) + + def addProxy(self, user, voter, proxy): + return self.app.post( + '/proxy/add', + environ_base={'USER_ROLES': user}, + data=dict(voter=voter, proxy=proxy) + ) + + def revokeProxy(self, user, id): + return self.app.post( + '/proxy/revoke', + environ_base={'USER_ROLES': user}, + data=dict(id=id) + ) + def buildResultText(self, motiontext, yes, no, abstain): return '
'+motiontext+'
\n\nYes '+str(yes)+'
'\
+ '\nNo '+str(no)+'
'\
@@ -37,47 +76,39 @@ class BasicTest(TestCase):
# functions to clear database
def db_clear(self):
- db = postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD"))
- with app.open_resource('sql/schema.sql', mode='r') as f:
- db.execute(f.read())
+ 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):
- db = postgresql.open(app.config.get("DATABASE"), user=app.config.get("USER"), password=app.config.get("PASSWORD"))
- with app.open_resource('sql/sample_data.sql', mode='r') as f:
- db.execute(f.read())
+ 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):
-
+
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()
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= '
A third motion
'\ @@ -88,7 +119,9 @@ class GeneralTests(BasicTest): self.assertIn(str.encode(testtext), result.data) testtext= 'A second motion
'\ @@ -98,7 +131,9 @@ class GeneralTests(BasicTest): self.assertIn(str.encode(testtext), result.data) testtext= 'My special motion
'\ @@ -106,6 +141,8 @@ class GeneralTests(BasicTest): + '\nNo 1A second motion
\n