10
10
import tempfile
11
11
import unittest
12
12
from typing import Any , Dict , Iterable , List , Optional
13
- from unittest .mock import call , patch
14
13
15
14
from tests import utils
16
15
from tests .repository_simulator import RepositorySimulator
@@ -90,19 +89,19 @@ def _assert_targets_files_exist(self, filenames: Iterable[str]) -> None:
90
89
"consistent_snaphot disabled" : {
91
90
"consistent_snapshot" : False ,
92
91
"calls" : [
93
- call ("root" , 3 ),
94
- call ("timestamp" , None ),
95
- call ("snapshot" , None ),
96
- call ("targets" , None ),
92
+ ("root" , 3 ),
93
+ ("timestamp" , None ),
94
+ ("snapshot" , None ),
95
+ ("targets" , None ),
97
96
],
98
97
},
99
98
"consistent_snaphot enabled" : {
100
99
"consistent_snapshot" : True ,
101
100
"calls" : [
102
- call ("root" , 3 ),
103
- call ("timestamp" , None ),
104
- call ("snapshot" , 1 ),
105
- call ("targets" , 1 ),
101
+ ("root" , 3 ),
102
+ ("timestamp" , None ),
103
+ ("snapshot" , 1 ),
104
+ ("targets" , 1 ),
106
105
],
107
106
},
108
107
}
@@ -117,15 +116,14 @@ def test_top_level_roles_update(self, test_case_data: Dict[str, Any]):
117
116
sim = self ._init_repo (consistent_snapshot )
118
117
updater = self ._init_updater (sim )
119
118
120
- with patch .object (
121
- sim , "_fetch_metadata" , wraps = sim ._fetch_metadata
122
- ) as wrapped_fetch :
123
- updater .refresh ()
119
+ # cleanup fetch tracker metadata
120
+ sim .fetch_tracker .metadata .clear ()
121
+ updater .refresh ()
124
122
125
- # metadata files are fetched with the expected version (or None)
126
- self .assertListEqual (wrapped_fetch . call_args_list , expected_calls )
127
- # metadata files are always persisted without a version prefix
128
- self ._assert_metadata_files_exist (TOP_LEVEL_ROLE_NAMES )
123
+ # metadata files are fetched with the expected version (or None)
124
+ self .assertListEqual (sim . fetch_tracker . metadata , expected_calls )
125
+ # metadata files are always persisted without a version prefix
126
+ self ._assert_metadata_files_exist (TOP_LEVEL_ROLE_NAMES )
129
127
130
128
self ._cleanup_dir (self .metadata_dir )
131
129
@@ -147,7 +145,7 @@ def test_delegated_roles_update(self, test_case_data: Dict[str, Any]):
147
145
consistent_snapshot : bool = test_case_data ["consistent_snapshot" ]
148
146
expected_version : Optional [int ] = test_case_data ["expected_version" ]
149
147
rolenames = ["role1" , ".." , "." ]
150
- expected_calls = [call (role , expected_version ) for role in rolenames ]
148
+ expected_calls = [(role , expected_version ) for role in rolenames ]
151
149
152
150
sim = self ._init_repo (consistent_snapshot )
153
151
# Add new delegated targets
@@ -159,15 +157,14 @@ def test_delegated_roles_update(self, test_case_data: Dict[str, Any]):
159
157
updater = self ._init_updater (sim )
160
158
updater .refresh ()
161
159
162
- with patch .object (
163
- sim , "_fetch_metadata" , wraps = sim ._fetch_metadata
164
- ) as wrapped_fetch :
165
- # trigger updater to fetch the delegated metadata
166
- updater .get_targetinfo ("anything" )
167
- # metadata files are fetched with the expected version (or None)
168
- self .assertListEqual (wrapped_fetch .call_args_list , expected_calls )
169
- # metadata files are always persisted without a version prefix
170
- self ._assert_metadata_files_exist (rolenames )
160
+ # cleanup fetch tracker metadata
161
+ sim .fetch_tracker .metadata .clear ()
162
+ # trigger updater to fetch the delegated metadata
163
+ updater .get_targetinfo ("anything" )
164
+ # metadata files are fetched with the expected version (or None)
165
+ self .assertListEqual (sim .fetch_tracker .metadata , expected_calls )
166
+ # metadata files are always persisted without a version prefix
167
+ self ._assert_metadata_files_exist (rolenames )
171
168
172
169
self ._cleanup_dir (self .metadata_dir )
173
170
@@ -176,16 +173,19 @@ def test_delegated_roles_update(self, test_case_data: Dict[str, Any]):
176
173
"consistent_snapshot" : False ,
177
174
"prefix_targets" : True ,
178
175
"hash_algo" : None ,
176
+ "targetpaths" : ["file" , "file.txt" , "..file.ext" , "f.le" ],
179
177
},
180
178
"consistent_snaphot enabled without prefixed targets" : {
181
179
"consistent_snapshot" : True ,
182
180
"prefix_targets" : False ,
183
181
"hash_algo" : None ,
182
+ "targetpaths" : ["file" , "file.txt" , "..file.ext" , "f.le" ],
184
183
},
185
184
"consistent_snaphot enabled with prefixed targets" : {
186
185
"consistent_snapshot" : True ,
187
186
"prefix_targets" : True ,
188
187
"hash_algo" : "sha256" ,
188
+ "targetpaths" : ["file" , "file.txt" , "..file.ext" , "f.le" ],
189
189
},
190
190
}
191
191
@@ -197,7 +197,7 @@ def test_download_targets(self, test_case_data: Dict[str, Any]):
197
197
consistent_snapshot : bool = test_case_data ["consistent_snapshot" ]
198
198
prefix_targets_with_hash : bool = test_case_data ["prefix_targets" ]
199
199
hash_algo : Optional [str ] = test_case_data ["hash_algo" ]
200
- targetpaths = [ "file" , "file.txt" , "..file.ext" , "f.le " ]
200
+ targetpaths : List [ str ] = test_case_data [ "targetpaths " ]
201
201
202
202
sim = self ._init_repo (consistent_snapshot , prefix_targets_with_hash )
203
203
# Add targets to repository
@@ -210,23 +210,20 @@ def test_download_targets(self, test_case_data: Dict[str, Any]):
210
210
updater .config .prefix_targets_with_hash = prefix_targets_with_hash
211
211
updater .refresh ()
212
212
213
- with patch .object (
214
- sim , "_fetch_target" , wraps = sim ._fetch_target
215
- ) as wrapped_fetch_target :
216
-
217
- for targetpath in targetpaths :
218
- info = updater .get_targetinfo (targetpath )
219
- updater .download_target (info )
220
- expected_prefix = (
221
- None if not hash_algo else info .hashes [hash_algo ]
222
- )
223
- # files are fetched with the expected hash prefix (or None)
224
- wrapped_fetch_target .assert_called_once_with (
225
- info .path , expected_prefix
226
- )
227
- # target files are always persisted without hash prefix
228
- self ._assert_targets_files_exist ([info .path ])
229
- wrapped_fetch_target .reset_mock ()
213
+ for targetpath in targetpaths :
214
+ info = updater .get_targetinfo (targetpath )
215
+ updater .download_target (info )
216
+
217
+ # target files are always persisted without hash prefix
218
+ self ._assert_targets_files_exist ([info .path ])
219
+
220
+ # files are fetched with the expected hash prefix (or None)
221
+ expected_fetches = [
222
+ (targetpath , None if not hash_algo else info .hashes [hash_algo ])
223
+ ]
224
+
225
+ self .assertListEqual (sim .fetch_tracker .targets , expected_fetches )
226
+ sim .fetch_tracker .targets .clear ()
230
227
231
228
self ._cleanup_dir (self .targets_dir )
232
229
0 commit comments