diff --git a/swh/model/model.py b/swh/model/model.py --- a/swh/model/model.py +++ b/swh/model/model.py @@ -1093,13 +1093,3 @@ d[swhid_key] = CoreSWHID.from_string(d[swhid_key]) return super().from_dict(d) - - def unique_key(self) -> KeyType: - return { - "target": str(self.target), - "authority_type": self.authority.type.value, - "authority_url": self.authority.url, - "discovery_date": str(self.discovery_date), - "fetcher_name": self.fetcher.name, - "fetcher_version": self.fetcher.version, - } diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -768,32 +768,31 @@ ) +authority_example = { + "type": "forge", + "url": "https://forge.softwareheritage.org/", +} +fetcher_example = { + "name": "swh-phabricator-metadata-fetcher", + "version": "0.0.1", +} +metadata_example = { + "target": "swh:1:cnt:568aaf43d83b2c3df8067f3bedbb97d83260be6d", + "discovery_date": datetime.datetime( + 2021, 1, 25, 11, 27, 51, tzinfo=datetime.timezone.utc + ), + "authority": authority_example, + "fetcher": fetcher_example, + "format": "json", + "metadata": b'{"foo": "bar"}', +} + + class RawExtrinsicMetadataIdentifier(unittest.TestCase): def setUp(self): super().setUp() - self.authority = { - "type": "forge", - "url": "https://forge.softwareheritage.org/", - } - self.fetcher = { - "name": "swh-phabricator-metadata-fetcher", - "version": "0.0.1", - } - - self.minimal = { - "type": "content", - "target": ExtendedSWHID.from_string( - "swh:1:cnt:568aaf43d83b2c3df8067f3bedbb97d83260be6d" - ), - "discovery_date": datetime.datetime( - 2021, 1, 25, 11, 27, 51, tzinfo=datetime.timezone.utc - ), - "authority": self.authority, - "fetcher": self.fetcher, - "format": "json", - "metadata": b'{"foo": "bar"}', - } + self.minimal = metadata_example self.maximal = { **self.minimal, "origin": "https://forge.softwareheritage.org/source/swh-model/", diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py --- a/swh/model/tests/test_model.py +++ b/swh/model/tests/test_model.py @@ -48,6 +48,7 @@ from swh.model.tests.test_identifiers import ( content_example, directory_example, + metadata_example, origin_example, release_example, revision_example, @@ -94,6 +95,10 @@ assert Release.from_dict({**release_example, "id": id_}).unique_key() == id_ assert Revision.from_dict({**revision_example, "id": id_}).unique_key() == id_ assert Directory.from_dict({**directory_example, "id": id_}).unique_key() == id_ + assert ( + RawExtrinsicMetadata.from_dict({**metadata_example, "id": id_}).unique_key() + == id_ + ) cont = Content.from_data(b"foo") assert cont.unique_key().hex() == "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"