Commit e8879e9fd86163c78846f8719eb97f5fc2f6d836
1 parent
5b7c87fe
Exists in
master
and in
4 other branches
New get_admin tiny method
Showing
1 changed file
with
7 additions
and
3 deletions
Show diff stats
tests/backend_tests.py
... | ... | @@ -50,10 +50,14 @@ class DbMgrTestCase(BaseTestCase): |
50 | 50 | |
51 | 51 | |
52 | 52 | class AuthModelTestCase(BaseTestCase): |
53 | + | |
53 | 54 | def skip_if_no_sqlitememory(self): |
54 | 55 | if 'memory' not in self.app.config['SQLALCHEMY_DATABASE_URI']: |
55 | 56 | self.skipTest("Needs in memory sqlite") |
56 | 57 | |
58 | + def get_admin(self): | |
59 | + return User.query.filter(User.name == 'admin').one() | |
60 | + | |
57 | 61 | def setUp(self): |
58 | 62 | BaseTestCase.setUp(self) |
59 | 63 | self.skip_if_no_sqlitememory() |
... | ... | @@ -67,15 +71,15 @@ class AuthModelTestCase(BaseTestCase): |
67 | 71 | self.assertTrue(True) |
68 | 72 | |
69 | 73 | def test_setrole(self): |
70 | - admin = User.query.filter(User.name == 'admin').one() | |
74 | + admin = self.get_admin() | |
71 | 75 | admin.set_role("ADMIN") |
72 | 76 | db.session.commit() |
73 | - admin = User.query.filter(User.name == 'admin').one() | |
77 | + admin = self.get_admin() | |
74 | 78 | self.assertTrue(admin is not None) |
75 | 79 | self.assertTrue(admin.has_role("ADMIN")) |
76 | 80 | self.assertFalse(admin.has_role("SERVICE")) |
77 | 81 | |
78 | 82 | def test_setrole_valueerror(self): |
79 | - admin = User(email='me@nowhere.org', name='me', login='me', password='me', role='admin') | |
83 | + admin = self.get_admin() | |
80 | 84 | with self.assertRaises(ValueError) as ve: |
81 | 85 | admin.set_role("NOSUCHROLE") | ... | ... |