@@ -246,7 +246,52 @@ def test_metadata_base(self):
246246 is_expired = md .signed .is_expired ()
247247 self .assertFalse (is_expired )
248248 md .signed .expires = expires
249-
249+
250+
251+ def test_metafile_class (self ):
252+ # Test from_dict and to_dict with all attributes.
253+ data = {
254+ "hashes" : {
255+ "sha256" : "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab"
256+ },
257+ "length" : 515 ,
258+ "version" : 1
259+ }
260+ metafile_obj = MetadataFile .from_dict (copy .copy (data ))
261+ self .assertEqual (metafile_obj .to_dict (), data )
262+
263+ # Test from_dict and to_dict without length.
264+ del data ["length" ]
265+ metafile_obj = MetadataFile .from_dict (copy .copy (data ))
266+ self .assertEqual (metafile_obj .to_dict (), data )
267+
268+ # Test from_dict and to_dict without length and hashes.
269+ del data ["hashes" ]
270+ metafile_obj = MetadataFile .from_dict (copy .copy (data ))
271+ self .assertEqual (metafile_obj .to_dict (), data )
272+
273+
274+ def test_targetfile_class (self ):
275+ # Test from_dict and to_dict with all attributes.
276+ data = {
277+ "custom" : {
278+ "file_permissions" : "0644"
279+ },
280+ "hashes" : {
281+ "sha256" : "65b8c67f51c993d898250f40aa57a317d854900b3a04895464313e48785440da" ,
282+ "sha512" : "467430a68afae8e9f9c0771ea5d78bf0b3a0d79a2d3d3b40c69fde4dd42c461448aef76fcef4f5284931a1ffd0ac096d138ba3a0d6ca83fa8d7285a47a296f77"
283+ },
284+ "length" : 31
285+ }
286+ targetfile_obj = TargetFile .from_dict (copy .copy (data ))
287+ self .assertEqual (targetfile_obj .to_dict (), data )
288+
289+ # Test from_dict and to_dict without custom.
290+ del data ["custom" ]
291+ targetfile_obj = TargetFile .from_dict (copy .copy (data ))
292+ self .assertEqual (targetfile_obj .to_dict (), data )
293+
294+
250295 def test_metadata_snapshot (self ):
251296 snapshot_path = os .path .join (
252297 self .repo_dir , 'metadata' , 'snapshot.json' )
0 commit comments