From e8879e9fd86163c78846f8719eb97f5fc2f6d836 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Thu, 15 Apr 2021 15:38:26 +0200 Subject: [PATCH] New get_admin tiny method --- tests/backend_tests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/backend_tests.py b/tests/backend_tests.py index 7df939c..8e8ae0b 100644 --- a/tests/backend_tests.py +++ b/tests/backend_tests.py @@ -50,10 +50,14 @@ class DbMgrTestCase(BaseTestCase): class AuthModelTestCase(BaseTestCase): + def skip_if_no_sqlitememory(self): if 'memory' not in self.app.config['SQLALCHEMY_DATABASE_URI']: self.skipTest("Needs in memory sqlite") + def get_admin(self): + return User.query.filter(User.name == 'admin').one() + def setUp(self): BaseTestCase.setUp(self) self.skip_if_no_sqlitememory() @@ -67,15 +71,15 @@ class AuthModelTestCase(BaseTestCase): self.assertTrue(True) def test_setrole(self): - admin = User.query.filter(User.name == 'admin').one() + admin = self.get_admin() admin.set_role("ADMIN") db.session.commit() - admin = User.query.filter(User.name == 'admin').one() + admin = self.get_admin() self.assertTrue(admin is not None) self.assertTrue(admin.has_role("ADMIN")) self.assertFalse(admin.has_role("SERVICE")) def test_setrole_valueerror(self): - admin = User(email='me@nowhere.org', name='me', login='me', password='me', role='admin') + admin = self.get_admin() with self.assertRaises(ValueError) as ve: admin.set_role("NOSUCHROLE") -- libgit2 0.21.2