diff --git a/tests/test_updater_consistent_snapshot.py b/tests/test_updater_consistent_snapshot.py index 22fceefafd..4289d7b860 100644 --- a/tests/test_updater_consistent_snapshot.py +++ b/tests/test_updater_consistent_snapshot.py @@ -3,7 +3,7 @@ # Copyright 2021, New York University and the TUF contributors # SPDX-License-Identifier: MIT OR Apache-2.0 -"""Test ngclient Updater consistent snapshot""" +"""Test ngclient Updater toggling consistent snapshot""" import os import sys @@ -23,8 +23,9 @@ class TestConsistentSnapshot(unittest.TestCase): - """Test different combinations of consistent_snapshot and - prefix_targets_with_hash""" + """Test different combinations of 'consistent_snapshot' and + 'prefix_targets_with_hash' and verify that the correct URLs + are formed for each combination""" def setUp(self) -> None: self.temp_dir = tempfile.TemporaryDirectory() @@ -118,11 +119,11 @@ def test_top_level_roles_update(self, test_case_data: Dict[str, Any]): with patch.object( sim, "_fetch_metadata", wraps=sim._fetch_metadata - ) as wrapped_fetch_metadata: + ) as wrapped_fetch: updater.refresh() # metadata files are fetched with the expected version (or None) - wrapped_fetch_metadata.assert_has_calls(expected_calls) + self.assertListEqual(wrapped_fetch.call_args_list, expected_calls) # metadata files are always persisted without a version prefix self._assert_metadata_files_exist(TOP_LEVEL_ROLE_NAMES) @@ -160,11 +161,11 @@ def test_delegated_roles_update(self, test_case_data: Dict[str, Any]): with patch.object( sim, "_fetch_metadata", wraps=sim._fetch_metadata - ) as wrapped_fetch_metadata: + ) as wrapped_fetch: # trigger updater to fetch the delegated metadata updater.get_targetinfo("anything") # metadata files are fetched with the expected version (or None) - wrapped_fetch_metadata.assert_has_calls(expected_calls) + self.assertListEqual(wrapped_fetch.call_args_list, expected_calls) # metadata files are always persisted without a version prefix self._assert_metadata_files_exist(rolenames) @@ -181,7 +182,7 @@ def test_delegated_roles_update(self, test_case_data: Dict[str, Any]): "prefix_targets": False, "hash_algo": None, }, - "consistent_snaphot_enabled with prefixed targets": { + "consistent_snaphot enabled with prefixed targets": { "consistent_snapshot": True, "prefix_targets": True, "hash_algo": "sha256", @@ -203,29 +204,29 @@ def test_download_targets(self, test_case_data: Dict[str, Any]): for targetpath in targetpaths: sim.targets.version += 1 sim.add_target("targets", b"content", targetpath) - sim.update_snapshot() + sim.update_snapshot() updater = self._init_updater(sim) updater.config.prefix_targets_with_hash = prefix_targets_with_hash updater.refresh() - for targetpath in targetpaths: - info = updater.get_targetinfo(targetpath) - - with patch.object( - sim, "_fetch_target", wraps=sim._fetch_target + with patch.object( + sim, "_fetch_target", wraps=sim._fetch_target ) as wrapped_fetch_target: + for targetpath in targetpaths: + info = updater.get_targetinfo(targetpath) updater.download_target(info) expected_prefix = ( None if not hash_algo else info.hashes[hash_algo] ) # files are fetched with the expected hash prefix (or None) - wrapped_fetch_target.assert_called_with( + wrapped_fetch_target.assert_called_once_with( info.path, expected_prefix ) # target files are always persisted without hash prefix self._assert_targets_files_exist([info.path]) + wrapped_fetch_target.reset_mock() self._cleanup_dir(self.targets_dir)