aboutsummaryrefslogtreecommitdiff
path: root/tests/base.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-05-15 07:24:18 +0200
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-05-15 07:24:18 +0200
commitdd059ad8a7d94ea6d03639e10e4d41c95dd1cebd (patch)
tree8aa3c0bf481a67717987af0710540668d3467ab0 /tests/base.py
parentThe list of inactive feeds is now sorted. (diff)
parenttesting special controller methods (diff)
downloadnewspipe-dd059ad8a7d94ea6d03639e10e4d41c95dd1cebd.tar.gz
newspipe-dd059ad8a7d94ea6d03639e10e4d41c95dd1cebd.tar.bz2
newspipe-dd059ad8a7d94ea6d03639e10e4d41c95dd1cebd.zip
Merged in jaesivsm/pyaggr3g470r (pull request #13)
introducing unittests !
Diffstat (limited to 'tests/base.py')
-rw-r--r--tests/base.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/base.py b/tests/base.py
new file mode 100644
index 00000000..d6f62583
--- /dev/null
+++ b/tests/base.py
@@ -0,0 +1,41 @@
+import os
+os.environ['PYAGG_TESTING'] = 'true'
+
+import unittest
+from bootstrap import db
+import runserver
+from tests.fixtures import populate_db, reset_db
+from werkzeug.exceptions import NotFound
+
+
+class BasePyaggTest(unittest.TestCase):
+ _contr_cls = None
+
+ def _get_from_contr(self, obj_id, user_id=None):
+ return self._contr_cls(user_id).get(id=obj_id).dump()
+
+ def _test_controller_rights(self, obj, user_id):
+ obj_id = obj['id']
+ self.assertEquals(obj, self._get_from_contr(obj_id))
+ self.assertEquals(obj, self._get_from_contr(obj_id, user_id))
+ # fetching non existent object
+ self.assertRaises(NotFound, self._get_from_contr, 99, user_id)
+ # fetching object with inexistent user
+ self.assertRaises(NotFound, self._get_from_contr, obj_id, 99)
+ # fetching object with wrong user
+ self.assertRaises(NotFound, self._get_from_contr, obj_id, user_id + 1)
+ self.assertRaises(NotFound, self._contr_cls().delete, 99)
+ self.assertRaises(NotFound, self._contr_cls(user_id).delete, 99)
+ self.assertEquals(obj['id'],
+ self._contr_cls(user_id).delete(obj_id).id)
+ self.assertRaises(NotFound, self._contr_cls(user_id).delete, obj_id)
+
+ def setUp(self):
+ populate_db(db)
+
+ def tearDown(self):
+ reset_db(db)
+
+
+if __name__ == '__main__':
+ unittest.main()
bgstack15