File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,10 @@ def test_metadata_snapshot(self):
232
232
self .assertNotEqual (snapshot .signed .meta , fileinfo )
233
233
snapshot .signed .update ('role1' , 2 , 123 , hashes )
234
234
self .assertEqual (snapshot .signed .meta , fileinfo )
235
+ # Update only version. Length and hashes are optional.
236
+ snapshot .signed .update ('role1' , 3 )
237
+ fileinfo ['role1.json' ] = {'version' : 3 }
238
+ self .assertEqual (snapshot .signed .meta , fileinfo )
235
239
236
240
237
241
def test_metadata_timestamp (self ):
@@ -267,6 +271,10 @@ def test_metadata_timestamp(self):
267
271
self .assertNotEqual (timestamp .signed .meta ['snapshot.json' ], fileinfo )
268
272
timestamp .signed .update (2 , 520 , hashes )
269
273
self .assertEqual (timestamp .signed .meta ['snapshot.json' ], fileinfo )
274
+ # Update only version. Length and hashes are optional.
275
+ timestamp .signed .update (3 )
276
+ fileinfo = {'version' : 3 }
277
+ self .assertEqual (timestamp .signed .meta ['snapshot.json' ], fileinfo )
270
278
271
279
272
280
def test_metadata_root (self ):
Original file line number Diff line number Diff line change @@ -431,7 +431,7 @@ class Timestamp(Signed):
431
431
'<HASH ALGO 1>': '<SNAPSHOT METADATA FILE HASH 1>',
432
432
'<HASH ALGO 2>': '<SNAPSHOT METADATA FILE HASH 2>',
433
433
...
434
- }
434
+ } // optional
435
435
}
436
436
}
437
437
@@ -455,13 +455,16 @@ def to_dict(self) -> JsonDict:
455
455
456
456
457
457
# Modification.
458
- def update (self , version : int , length : int , hashes : JsonDict ) -> None :
458
+ def update (self , version : int , length : Optional [int ] = None ,
459
+ hashes : Optional [JsonDict ] = None ) -> None :
459
460
"""Assigns passed info about snapshot metadata to meta dict. """
460
- self .meta ['snapshot.json' ] = {
461
- 'version' : version ,
462
- 'length' : length ,
463
- 'hashes' : hashes
464
- }
461
+
462
+ self .meta ['snapshot.json' ] = {'version' : version }
463
+ if length is not None :
464
+ self .meta ['snapshot.json' ]['length' ] = length
465
+
466
+ if hashes is not None :
467
+ self .meta ['snapshot.json' ]['hashes' ] = hashes
465
468
466
469
467
470
class Snapshot (Signed ):
You can’t perform that action at this time.
0 commit comments