Skip to content

Commit cc2326d

Browse files
authored
Merge pull request #1736 from lukpueh/rm-metadata-api-update
Metadata API: Remove 3 'update' methods + tests
2 parents 1f3654f + f22f357 commit cc2326d

File tree

2 files changed

+0
-91
lines changed

2 files changed

+0
-91
lines changed

tests/test_api.py

-75
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
Delegations,
3333
Key,
3434
Metadata,
35-
MetaFile,
3635
Root,
3736
Snapshot,
3837
TargetFile,
@@ -297,56 +296,6 @@ def test_metadata_base(self) -> None:
297296
with self.assertRaises(ValueError):
298297
Metadata.from_dict(data)
299298

300-
def test_metadata_snapshot(self) -> None:
301-
snapshot_path = os.path.join(self.repo_dir, "metadata", "snapshot.json")
302-
snapshot = Metadata[Snapshot].from_file(snapshot_path)
303-
304-
# Create a MetaFile instance representing what we expect
305-
# the updated data to be.
306-
hashes = {
307-
"sha256": "c2986576f5fdfd43944e2b19e775453b96748ec4fe2638a6d2f32f1310967095"
308-
}
309-
fileinfo = MetaFile(2, 123, hashes)
310-
311-
self.assertNotEqual(
312-
snapshot.signed.meta["role1.json"].to_dict(), fileinfo.to_dict()
313-
)
314-
snapshot.signed.update("role1", fileinfo)
315-
self.assertEqual(
316-
snapshot.signed.meta["role1.json"].to_dict(), fileinfo.to_dict()
317-
)
318-
319-
def test_metadata_timestamp(self) -> None:
320-
timestamp_path = os.path.join(
321-
self.repo_dir, "metadata", "timestamp.json"
322-
)
323-
timestamp = Metadata[Timestamp].from_file(timestamp_path)
324-
325-
self.assertEqual(timestamp.signed.version, 1)
326-
timestamp.signed.bump_version()
327-
self.assertEqual(timestamp.signed.version, 2)
328-
329-
self.assertEqual(timestamp.signed.expires, datetime(2030, 1, 1, 0, 0))
330-
timestamp.signed.bump_expiration()
331-
self.assertEqual(timestamp.signed.expires, datetime(2030, 1, 2, 0, 0))
332-
timestamp.signed.bump_expiration(timedelta(days=365))
333-
self.assertEqual(timestamp.signed.expires, datetime(2031, 1, 2, 0, 0))
334-
335-
# Create a MetaFile instance representing what we expect
336-
# the updated data to be.
337-
hashes = {
338-
"sha256": "0ae9664468150a9aa1e7f11feecb32341658eb84292851367fea2da88e8a58dc"
339-
}
340-
fileinfo = MetaFile(2, 520, hashes)
341-
342-
self.assertNotEqual(
343-
timestamp.signed.snapshot_meta.to_dict(), fileinfo.to_dict()
344-
)
345-
timestamp.signed.update(fileinfo)
346-
self.assertEqual(
347-
timestamp.signed.snapshot_meta.to_dict(), fileinfo.to_dict()
348-
)
349-
350299
def test_metadata_verify_delegate(self) -> None:
351300
root_path = os.path.join(self.repo_dir, "metadata", "root.json")
352301
root = Metadata[Root].from_file(root_path)
@@ -505,30 +454,6 @@ def test_is_target_in_pathpattern(self) -> None:
505454
DelegatedRole._is_target_in_pathpattern(targetpath, pathpattern)
506455
)
507456

508-
def test_metadata_targets(self) -> None:
509-
targets_path = os.path.join(self.repo_dir, "metadata", "targets.json")
510-
targets = Metadata[Targets].from_file(targets_path)
511-
512-
# Create a fileinfo dict representing the expected updated data.
513-
filename = "file2.txt"
514-
hashes = {
515-
"sha256": "141f740f53781d1ca54b8a50af22cbf74e44c21a998fa2a8a05aaac2c002886b",
516-
"sha512": "ef5beafa16041bcdd2937140afebd485296cd54f7348ecd5a4d035c09759608de467a7ac0eb58753d0242df873c305e8bffad2454aa48f44480f15efae1cacd0",
517-
}
518-
519-
fileinfo = TargetFile(length=28, hashes=hashes, path=filename)
520-
521-
# Assert that data is not aleady equal
522-
self.assertNotEqual(
523-
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()
524-
)
525-
# Update an already existing fileinfo
526-
targets.signed.update(fileinfo)
527-
# Verify that data is updated
528-
self.assertEqual(
529-
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()
530-
)
531-
532457
def test_targets_key_api(self) -> None:
533458
targets_path = os.path.join(self.repo_dir, "metadata", "targets.json")
534459
targets: Targets = Metadata[Targets].from_file(targets_path).signed

tuf/api/metadata.py

-16
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,6 @@ def to_dict(self) -> Dict[str, Any]:
10021002
res_dict["meta"] = {"snapshot.json": self.snapshot_meta.to_dict()}
10031003
return res_dict
10041004

1005-
# Modification.
1006-
def update(self, snapshot_meta: MetaFile) -> None:
1007-
"""Assigns passed info about snapshot metadata."""
1008-
self.snapshot_meta = snapshot_meta
1009-
10101005

10111006
class Snapshot(Signed):
10121007
"""A container for the signed part of snapshot metadata.
@@ -1058,12 +1053,6 @@ def to_dict(self) -> Dict[str, Any]:
10581053
snapshot_dict["meta"] = meta_dict
10591054
return snapshot_dict
10601055

1061-
# Modification.
1062-
def update(self, rolename: str, role_info: MetaFile) -> None:
1063-
"""Assigns passed (delegated) targets role info to meta dict."""
1064-
metadata_fn = f"{rolename}.json"
1065-
self.meta[metadata_fn] = role_info
1066-
10671056

10681057
class DelegatedRole(Role):
10691058
"""A container with information about a delegated role.
@@ -1472,11 +1461,6 @@ def to_dict(self) -> Dict[str, Any]:
14721461
targets_dict["delegations"] = self.delegations.to_dict()
14731462
return targets_dict
14741463

1475-
# Modification.
1476-
def update(self, fileinfo: TargetFile) -> None:
1477-
"""Assigns passed target file info to meta dict."""
1478-
self.targets[fileinfo.path] = fileinfo
1479-
14801464
def add_key(self, role: str, key: Key) -> None:
14811465
"""Adds new signing key for delegated role 'role'.
14821466

0 commit comments

Comments
 (0)