Commit 5b7c87fe890e573dd87098a6b6dbc2747ff74cfb
1 parent
2bf8caae
Exists in
master
and in
4 other branches
Run auth tests on sqlite:memory: db
Showing
1 changed file
with
21 additions
and
3 deletions
Show diff stats
tests/backend_tests.py
... | ... | @@ -5,13 +5,16 @@ from app import create_app, db_mgr, db |
5 | 5 | from app.auth.models import User |
6 | 6 | |
7 | 7 | |
8 | + | |
9 | + | |
8 | 10 | class BaseTestCase(unittest.TestCase): |
9 | 11 | def setUp(self): |
10 | 12 | # configure data base |
11 | 13 | self.app = create_app(TestConfig) |
12 | 14 | self.app_context = self.app.app_context() |
13 | 15 | self.app_context.push() |
14 | - # TODO: shall we always copy db from resources ? | |
16 | + # TODO: shall we always copy db from resources sqlite file ? | |
17 | + # that would allow us to run all tests in sqlite:memory: | |
15 | 18 | # db.create_all() |
16 | 19 | # admin = User(email='admin@nowhere.org', name='admin', login='admin', password='admin', role='admin') |
17 | 20 | # db.session.add(admin) |
... | ... | @@ -47,12 +50,27 @@ class DbMgrTestCase(BaseTestCase): |
47 | 50 | |
48 | 51 | |
49 | 52 | class AuthModelTestCase(BaseTestCase): |
53 | + def skip_if_no_sqlitememory(self): | |
54 | + if 'memory' not in self.app.config['SQLALCHEMY_DATABASE_URI']: | |
55 | + self.skipTest("Needs in memory sqlite") | |
56 | + | |
57 | + def setUp(self): | |
58 | + BaseTestCase.setUp(self) | |
59 | + self.skip_if_no_sqlitememory() | |
60 | + db.create_all() | |
61 | + admin = User(email='admin@nowhere.org', name='admin', login='admin', role='admin') | |
62 | + db.session.add(admin) | |
63 | + db.session.commit() | |
64 | + | |
65 | + def test_in_memory(self): | |
66 | + self.app.logger.info("In memory Sqlite DB for tests") | |
67 | + self.assertTrue(True) | |
50 | 68 | |
51 | 69 | def test_setrole(self): |
52 | - admin = User.query.filter(User.name == 'admin').one_or_none() | |
70 | + admin = User.query.filter(User.name == 'admin').one() | |
53 | 71 | admin.set_role("ADMIN") |
54 | 72 | db.session.commit() |
55 | - admin = User.query.filter(User.name == 'admin').one_or_none() | |
73 | + admin = User.query.filter(User.name == 'admin').one() | |
56 | 74 | self.assertTrue(admin is not None) |
57 | 75 | self.assertTrue(admin.has_role("ADMIN")) |
58 | 76 | self.assertFalse(admin.has_role("SERVICE")) | ... | ... |