From 2185f9308e61a938e7da802451f1d09ed9adaa28 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <vlorentz@softwareheritage.org>
Date: Mon, 8 Feb 2021 15:40:21 +0100
Subject: [PATCH] model: Remove override of RawExtrinsicMetadata.unique_key(),
 so it now returns the hash.

---
 swh/model/model.py                  | 10 -------
 swh/model/tests/test_identifiers.py | 43 ++++++++++++++---------------
 swh/model/tests/test_model.py       |  5 ++++
 3 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/swh/model/model.py b/swh/model/model.py
index baa51a7e..6df310a0 100644
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -1093,13 +1093,3 @@ class RawExtrinsicMetadata(HashableObject, BaseModel):
                 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
index a2350656..3ba57086 100644
--- a/swh/model/tests/test_identifiers.py
+++ b/swh/model/tests/test_identifiers.py
@@ -768,32 +768,31 @@ class SnapshotIdentifier(unittest.TestCase):
         )
 
 
+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
index 8325bf51..2c84d714 100644
--- a/swh/model/tests/test_model.py
+++ b/swh/model/tests/test_model.py
@@ -48,6 +48,7 @@ from swh.model.model import (
 from swh.model.tests.test_identifiers import (
     content_example,
     directory_example,
+    metadata_example,
     origin_example,
     release_example,
     revision_example,
@@ -94,6 +95,10 @@ def test_unique_key():
     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"
-- 
GitLab