diff options
Diffstat (limited to 'oslo_policy')
-rw-r--r-- | oslo_policy/tests/test_cache_handler.py | 28 |
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() |