summaryrefslogtreecommitdiff
path: root/oslo_policy
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-04-16 12:21:11 +0000
committerGerrit Code Review <review@openstack.org>2021-04-16 12:21:11 +0000
commit06a6fc8dd044d5ed9fa07d10282a6f52ba48eae5 (patch)
tree8a7c04c7808c1128461c46be450f7d5190e86b5a /oslo_policy
parent61f825a25d5e79196f558641191c0be35a0ef115 (diff)
parentd7323a088c5db6a5576c4c8ff41ccab463e65c8b (diff)
downloadoslo-policy-06a6fc8dd044d5ed9fa07d10282a6f52ba48eae5.tar.gz
Merge "Adding tests on cache handler"
Diffstat (limited to 'oslo_policy')
-rw-r--r--oslo_policy/tests/test_cache_handler.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/oslo_policy/tests/test_cache_handler.py b/oslo_policy/tests/test_cache_handler.py
index 867487d..3251009 100644
--- a/oslo_policy/tests/test_cache_handler.py
+++ b/oslo_policy/tests/test_cache_handler.py
@@ -16,8 +16,10 @@
"""Test the cache handler module"""
import os
+from unittest import mock
import fixtures
+import oslo_config
from oslotest import base as test_base
from oslo_policy import _cache_handler as _ch
@@ -64,3 +66,29 @@ class CacheHandlerTest(test_base.BaseTestCase):
reloaded, data = _ch.read_cached_file(file_cache, path)
self.assertTrue(reloaded)
+
+ @mock.patch.object(_ch, 'LOG')
+ def test_reloading_cache_with_permission_denied(self, mock_log):
+ file_cache = {}
+
+ path = os.path.join(self.tmpdir.path, 'tmpfile')
+ with open(path, 'w+') as fp:
+ fp.write('test')
+
+ os.chmod(path, 000)
+ self.assertRaises(
+ oslo_config.cfg.ConfigFilesPermissionDeniedError,
+ _ch.read_cached_file, file_cache, path)
+ mock_log.error.assert_called_once()
+
+ @mock.patch.object(_ch, 'LOG')
+ def test_reloading_on_removed_file(self, mock_log):
+ file_cache = {}
+
+ # don't actually create the file
+ path = os.path.join(self.tmpdir.path, 'tmpfile')
+
+ reloaded, data = _ch.read_cached_file(file_cache, path)
+ self.assertEqual({}, data)
+ self.assertTrue(reloaded)
+ mock_log.error.assert_called_once()