Skip to content
Snippets Groups Projects
Commit 975e9892 authored by vlorentz's avatar vlorentz
Browse files

model: Add a swhid() method to RawExtrinsicMetadata.

All other hashable objects but ExtId have one.

It will be used by swh-deposit.
parent 71be4617
No related branches found
Tags v2.2.0
No related merge requests found
...@@ -1098,6 +1098,13 @@ class RawExtrinsicMetadata(HashableObject, BaseModel): ...@@ -1098,6 +1098,13 @@ class RawExtrinsicMetadata(HashableObject, BaseModel):
return super().from_dict(d) return super().from_dict(d)
def swhid(self) -> ExtendedSWHID:
"""Returns a SWHID representing this RawExtrinsicMetadata object."""
return ExtendedSWHID(
object_type=SwhidExtendedObjectType.RAW_EXTRINSIC_METADATA,
object_id=self.id,
)
@attr.s(frozen=True, slots=True) @attr.s(frozen=True, slots=True)
class ExtID(HashableObject, BaseModel): class ExtID(HashableObject, BaseModel):
......
...@@ -21,6 +21,7 @@ from swh.model.identifiers import ( ...@@ -21,6 +21,7 @@ from swh.model.identifiers import (
content_identifier, content_identifier,
directory_identifier, directory_identifier,
origin_identifier, origin_identifier,
raw_extrinsic_metadata_identifier,
release_identifier, release_identifier,
revision_identifier, revision_identifier,
snapshot_identifier, snapshot_identifier,
...@@ -802,6 +803,14 @@ def test_origin_model_id_computation(): ...@@ -802,6 +803,14 @@ def test_origin_model_id_computation():
assert str(ori_model.swhid()) == "swh:1:ori:" + ori_id_str assert str(ori_model.swhid()) == "swh:1:ori:" + ori_id_str
def test_raw_extrinsic_metadata_model_id_computation():
emd_dict = metadata_example.copy()
emd_id_str = raw_extrinsic_metadata_identifier(emd_dict)
emd_model = RawExtrinsicMetadata.from_dict(emd_dict)
assert str(emd_model.swhid()) == "swh:1:emd:" + emd_id_str
@given(strategies.objects(split_content=True)) @given(strategies.objects(split_content=True))
def test_object_type(objtype_and_obj): def test_object_type(objtype_and_obj):
obj_type, obj = objtype_and_obj obj_type, obj = objtype_and_obj
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment