Skip to content

Commit 4213f46

Browse files
author
Jussi Kukkonen
committed
tests: Use Metadata generics where applicable
None of the changes are required but the advantages are: * Annotations for signed atributes in IDE are correct * The actual signed type gets verified at serialization time Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
1 parent 5e65d67 commit 4213f46

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

tests/test_api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_read_write_read_compare(self):
177177

178178
def test_sign_verify(self):
179179
root_path = os.path.join(self.repo_dir, 'metadata', 'root.json')
180-
root:Root = Metadata.from_file(root_path).signed
180+
root = Metadata.from_file(root_path, signed_type=Root).signed
181181

182182
# Locate the public keys we need from root
183183
targets_keyid = next(iter(root.roles["targets"].keyids))
@@ -189,7 +189,7 @@ def test_sign_verify(self):
189189

190190
# Load sample metadata (targets) and assert ...
191191
path = os.path.join(self.repo_dir, 'metadata', 'targets.json')
192-
metadata_obj = Metadata.from_file(path)
192+
metadata_obj = Metadata.from_file(path, signed_type=Targets)
193193

194194
# ... it has a single existing signature,
195195
self.assertEqual(len(metadata_obj.signatures), 1)
@@ -306,7 +306,7 @@ def test_targetfile_class(self):
306306
def test_metadata_snapshot(self):
307307
snapshot_path = os.path.join(
308308
self.repo_dir, 'metadata', 'snapshot.json')
309-
snapshot = Metadata.from_file(snapshot_path)
309+
snapshot = Metadata.from_file(snapshot_path, signed_type=Snapshot)
310310

311311
# Create a MetaFile instance representing what we expect
312312
# the updated data to be.
@@ -332,7 +332,7 @@ def test_metadata_snapshot(self):
332332
def test_metadata_timestamp(self):
333333
timestamp_path = os.path.join(
334334
self.repo_dir, 'metadata', 'timestamp.json')
335-
timestamp = Metadata.from_file(timestamp_path)
335+
timestamp = Metadata.from_file(timestamp_path, signed_type=Timestamp)
336336

337337
self.assertEqual(timestamp.signed.version, 1)
338338
timestamp.signed.bump_version()
@@ -441,7 +441,7 @@ def test_role_class(self):
441441
def test_metadata_root(self):
442442
root_path = os.path.join(
443443
self.repo_dir, 'metadata', 'root.json')
444-
root = Metadata.from_file(root_path)
444+
root = Metadata.from_file(root_path, signed_type=Root)
445445

446446
# Add a second key to root role
447447
root_key2 = import_ed25519_publickey_from_file(
@@ -579,7 +579,7 @@ def test_delegation_class(self):
579579
def test_metadata_targets(self):
580580
targets_path = os.path.join(
581581
self.repo_dir, 'metadata', 'targets.json')
582-
targets = Metadata.from_file(targets_path)
582+
targets = Metadata.from_file(targets_path, signed_type=Targets)
583583

584584
# Create a fileinfo dict representing what we expect the updated data to be
585585
filename = 'file2.txt'
@@ -668,7 +668,7 @@ def test_length_and_hash_validation(self):
668668
# for untrusted metadata file to verify.
669669
timestamp_path = os.path.join(
670670
self.repo_dir, 'metadata', 'timestamp.json')
671-
timestamp = Metadata.from_file(timestamp_path)
671+
timestamp = Metadata.from_file(timestamp_path, signed_type=Timestamp)
672672
snapshot_metafile = timestamp.signed.meta["snapshot.json"]
673673

674674
snapshot_path = os.path.join(
@@ -702,7 +702,7 @@ def test_length_and_hash_validation(self):
702702
# Test target files' hash and length verification
703703
targets_path = os.path.join(
704704
self.repo_dir, 'metadata', 'targets.json')
705-
targets = Metadata.from_file(targets_path)
705+
targets = Metadata.from_file(targets_path, signed_type=Targets)
706706
file1_targetfile = targets.signed.targets['file1.txt']
707707
filepath = os.path.join(
708708
self.repo_dir, 'targets', 'file1.txt')

0 commit comments

Comments
 (0)