File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed
Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -451,21 +451,23 @@ def test_delegated_role_class(self):
451451 with self .assertRaises (ValueError ):
452452 DelegatedRole .from_dict (role .copy ())
453453
454- # Test creating DelegatedRole only with "path_hash_prefixes"
454+ # Test creating DelegatedRole only with "path_hash_prefixes" (an empty one)
455455 del role ["paths" ]
456- DelegatedRole .from_dict (role .copy ())
457- role ["paths" ] = "foo"
456+ role ["path_hash_prefixes" ] = []
457+ role_obj = DelegatedRole .from_dict (role .copy ())
458+ self .assertEqual (role_obj .to_dict (), role )
458459
459- # Test creating DelegatedRole only with "paths"
460+ # Test creating DelegatedRole only with "paths" (now an empty one)
460461 del role ["path_hash_prefixes" ]
461- DelegatedRole .from_dict (role .copy ())
462- role ["path_hash_prefixes" ] = "foo"
462+ role ["paths" ] = []
463+ role_obj = DelegatedRole .from_dict (role .copy ())
464+ self .assertEqual (role_obj .to_dict (), role )
463465
464466 # Test creating DelegatedRole without "paths" and
465467 # "path_hash_prefixes" set
466468 del role ["paths" ]
467- del role [ "path_hash_prefixes" ]
468- DelegatedRole . from_dict ( role )
469+ role_obj = DelegatedRole . from_dict ( role . copy ())
470+ self . assertEqual ( role_obj . to_dict (), role )
469471
470472
471473 def test_delegation_class (self ):
Original file line number Diff line number Diff line change @@ -768,7 +768,7 @@ def __init__(
768768 super ().__init__ (keyids , threshold , unrecognized_fields )
769769 self .name = name
770770 self .terminating = terminating
771- if paths and path_hash_prefixes :
771+ if paths is not None and path_hash_prefixes is not None :
772772 raise ValueError (
773773 "Only one of the attributes 'paths' and"
774774 "'path_hash_prefixes' can be set!"
@@ -804,9 +804,9 @@ def to_dict(self) -> Dict[str, Any]:
804804 "terminating" : self .terminating ,
805805 ** base_role_dict ,
806806 }
807- if self .paths :
807+ if self .paths is not None :
808808 res_dict ["paths" ] = self .paths
809- elif self .path_hash_prefixes :
809+ elif self .path_hash_prefixes is not None :
810810 res_dict ["path_hash_prefixes" ] = self .path_hash_prefixes
811811 return res_dict
812812
You can’t perform that action at this time.
0 commit comments