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,10 +50,14 @@ class DbMgrTestCase(BaseTestCase): | ||
50 | 50 | ||
51 | 51 | ||
52 | class AuthModelTestCase(BaseTestCase): | 52 | class AuthModelTestCase(BaseTestCase): |
53 | + | ||
53 | def skip_if_no_sqlitememory(self): | 54 | def skip_if_no_sqlitememory(self): |
54 | if 'memory' not in self.app.config['SQLALCHEMY_DATABASE_URI']: | 55 | if 'memory' not in self.app.config['SQLALCHEMY_DATABASE_URI']: |
55 | self.skipTest("Needs in memory sqlite") | 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 | def setUp(self): | 61 | def setUp(self): |
58 | BaseTestCase.setUp(self) | 62 | BaseTestCase.setUp(self) |
59 | self.skip_if_no_sqlitememory() | 63 | self.skip_if_no_sqlitememory() |
@@ -67,15 +71,15 @@ class AuthModelTestCase(BaseTestCase): | @@ -67,15 +71,15 @@ class AuthModelTestCase(BaseTestCase): | ||
67 | self.assertTrue(True) | 71 | self.assertTrue(True) |
68 | 72 | ||
69 | def test_setrole(self): | 73 | def test_setrole(self): |
70 | - admin = User.query.filter(User.name == 'admin').one() | 74 | + admin = self.get_admin() |
71 | admin.set_role("ADMIN") | 75 | admin.set_role("ADMIN") |
72 | db.session.commit() | 76 | db.session.commit() |
73 | - admin = User.query.filter(User.name == 'admin').one() | 77 | + admin = self.get_admin() |
74 | self.assertTrue(admin is not None) | 78 | self.assertTrue(admin is not None) |
75 | self.assertTrue(admin.has_role("ADMIN")) | 79 | self.assertTrue(admin.has_role("ADMIN")) |
76 | self.assertFalse(admin.has_role("SERVICE")) | 80 | self.assertFalse(admin.has_role("SERVICE")) |
77 | 81 | ||
78 | def test_setrole_valueerror(self): | 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 | with self.assertRaises(ValueError) as ve: | 84 | with self.assertRaises(ValueError) as ve: |
81 | admin.set_role("NOSUCHROLE") | 85 | admin.set_role("NOSUCHROLE") |