diff options
| author | Akihiro Motoki <amotoki@gmail.com> | 2021-02-04 14:44:25 +0900 |
|---|---|---|
| committer | Akihiro Motoki <amotoki@gmail.com> | 2021-02-04 14:44:25 +0900 |
| commit | 4894d0eedeaf2809640b1a179eeee56e20d84d38 (patch) | |
| tree | d0a2c64f9aca08a13637f473c8394ee1a67615c4 /openstack_auth/tests | |
| parent | 944902c5c268fc1c287fb0a59f85e4c6674a7fb6 (diff) | |
| download | horizon-4894d0eedeaf2809640b1a179eeee56e20d84d38.tar.gz | |
Use override_settings decorator consistently
Some tests in openstack_auth test_policy explicity calls enable/disable
of settings class. We usually use @override_settings decorator and
it automatically disables setting overriding when existing the decorator.
Let's use it for consistency.
Change-Id: I30cc97798ddf0c55ef4e05c885ffc8ef99a7be81
Diffstat (limited to 'openstack_auth/tests')
| -rw-r--r-- | openstack_auth/tests/unit/test_policy.py | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/openstack_auth/tests/unit/test_policy.py b/openstack_auth/tests/unit/test_policy.py index fe8541cb0..a4fb20139 100644 --- a/openstack_auth/tests/unit/test_policy.py +++ b/openstack_auth/tests/unit/test_policy.py @@ -29,14 +29,15 @@ class PolicyLoaderTestCase(test.TestCase): self.assertIn('identity', enforcer) self.assertIn('compute', enforcer) - def test_nonexisting_policy_file_load(self): - policy_files = { + @test.override_settings( + POLICY_FILES={ 'dinosaur': 'no_godzilla.json', } + ) + def test_nonexisting_policy_file_load(self): policy.reset() - with self.settings(POLICY_FILES=policy_files): - enforcer = policy._get_enforcer() - self.assertEqual(0, len(enforcer)) + enforcer = policy._get_enforcer() + self.assertEqual(0, len(enforcer)) def test_policy_reset(self): policy._get_enforcer() @@ -94,19 +95,16 @@ class PolicyTestCaseNonAdmin(PolicyTestCase): self.assertTrue(value) +@test.override_settings( + POLICY_FILES={ + 'no_default': 'no_default_policy.json', + 'with_default': 'with_default_policy.json', + } +) class PolicyTestCheckCredentials(PolicyTestCase): _roles = [{'id': '1', 'name': 'member'}] def setUp(self): - policy_files = { - 'no_default': 'no_default_policy.json', - 'with_default': 'with_default_policy.json', - } - - override = self.settings(POLICY_FILES=policy_files) - override.enable() - self.addCleanup(override.disable) - mock_user = user.User(id=1, roles=self._roles, user_domain_id='admin_domain_id') patcher = mock.patch('openstack_auth.utils.get_user', @@ -185,18 +183,16 @@ class PolicyTestCaseAdmin(PolicyTestCase): self.assertTrue(value) +@test.override_settings( + POLICY_FILES={ + 'identity': 'policy.v3cloudsample.json', + 'compute': 'nova_policy.json', + } +) class PolicyTestCaseV3Admin(PolicyTestCase): _roles = [{'id': '1', 'name': 'admin'}] def setUp(self): - policy_files = { - 'identity': 'policy.v3cloudsample.json', - 'compute': 'nova_policy.json'} - - override = self.settings(POLICY_FILES=policy_files) - override.enable() - self.addCleanup(override.disable) - mock_user = user.User(id=1, roles=self._roles, user_domain_id='admin_domain_id') patcher = mock.patch('openstack_auth.utils.get_user', |
