Skip to content

Commit 60b54a6

Browse files
committed
tests: policy cache reacting to moving files
1 parent 1a5cf9d commit 60b54a6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

qrexec/tests/policy_cache.py

+41
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,47 @@ async def test_13_no_change(self, tmp_path, mock_parser):
9797

9898
assert not cache.outdated
9999

100+
@pytest.mark.asyncio
101+
async def test_14_policy_move(self, tmp_path, mock_parser):
102+
policy_path = tmp_path / "policy"
103+
policy_path.mkdir()
104+
cache = utils.PolicyCache(policy_path)
105+
cache.initialize_watcher()
106+
107+
mock_parser.assert_called_once_with(policy_path=policy_path)
108+
109+
assert not cache.outdated
110+
111+
file = tmp_path / "test"
112+
file.write_text("test")
113+
114+
await asyncio.sleep(1)
115+
116+
assert not cache.outdated
117+
118+
# move in
119+
file_moved = file.rename(policy_path / "test")
120+
121+
await asyncio.sleep(1)
122+
123+
assert cache.outdated
124+
125+
cache.get_policy()
126+
127+
assert not cache.outdated
128+
129+
# now move out
130+
file_moved.rename(file)
131+
132+
await asyncio.sleep(1)
133+
134+
assert cache.outdated
135+
136+
cache.get_policy()
137+
138+
call = unittest.mock.call(policy_path=policy_path)
139+
assert mock_parser.mock_calls == [call, call, call]
140+
100141
@pytest.mark.asyncio
101142
async def test_20_policy_updates(self, tmp_path, mock_parser):
102143
cache = utils.PolicyCache(tmp_path)

0 commit comments

Comments
 (0)