summaryrefslogtreecommitdiff
path: root/oslo_policy
diff options
context:
space:
mode:
authorHervé Beraud <hberaud@redhat.com>2020-08-18 19:07:48 +0200
committerStephen Finucane <sfinucan@redhat.com>2021-02-09 14:32:16 +0000
commitd7323a088c5db6a5576c4c8ff41ccab463e65c8b (patch)
tree9135866a981dcf63cf276bec2bcc2a9ab91e2cec /oslo_policy
parent9919f1317c037163d0f31232991cca261881b66b (diff)
downloadoslo-policy-d7323a088c5db6a5576c4c8ff41ccab463e65c8b.tar.gz
Adding tests on cache handler
New tests are: - Permission denied - File not found Change-Id: I6d3343319ca6519fd9d215f2e8d3fa38516e9f4d
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()