From 60b54a65c99b256c64c0741517eb1d0961bed3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 28 Jun 2024 01:22:51 +0200 Subject: [PATCH] tests: policy cache reacting to moving files --- qrexec/tests/policy_cache.py | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/qrexec/tests/policy_cache.py b/qrexec/tests/policy_cache.py index a912b889..b1ca4634 100644 --- a/qrexec/tests/policy_cache.py +++ b/qrexec/tests/policy_cache.py @@ -97,6 +97,47 @@ async def test_13_no_change(self, tmp_path, mock_parser): assert not cache.outdated + @pytest.mark.asyncio + async def test_14_policy_move(self, tmp_path, mock_parser): + policy_path = tmp_path / "policy" + policy_path.mkdir() + cache = utils.PolicyCache(policy_path) + cache.initialize_watcher() + + mock_parser.assert_called_once_with(policy_path=policy_path) + + assert not cache.outdated + + file = tmp_path / "test" + file.write_text("test") + + await asyncio.sleep(1) + + assert not cache.outdated + + # move in + file_moved = file.rename(policy_path / "test") + + await asyncio.sleep(1) + + assert cache.outdated + + cache.get_policy() + + assert not cache.outdated + + # now move out + file_moved.rename(file) + + await asyncio.sleep(1) + + assert cache.outdated + + cache.get_policy() + + call = unittest.mock.call(policy_path=policy_path) + assert mock_parser.mock_calls == [call, call, call] + @pytest.mark.asyncio async def test_20_policy_updates(self, tmp_path, mock_parser): cache = utils.PolicyCache(tmp_path)