From 00b22ca5cf7d18c918050da5d16d5c7eeb92ab27 Mon Sep 17 00:00:00 2001
From: NolanB <nboukachab@teklia.com>
Date: Wed, 31 Aug 2022 10:34:54 +0200
Subject: [PATCH] Add test_list_metadata() method to metadata.py

---
 arkindex_worker/worker/metadata.py          | 33 +++++++++++++++++++--
 tests/test_elements_worker/test_metadata.py | 18 +++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/arkindex_worker/worker/metadata.py b/arkindex_worker/worker/metadata.py
index f5865304..1147bc2d 100644
--- a/arkindex_worker/worker/metadata.py
+++ b/arkindex_worker/worker/metadata.py
@@ -105,10 +105,39 @@ class MetaDataMixin(object):
 
         return metadata["id"]
 
+    def create_metadatabulk(
+        self,
+        element: Element,
+        metadata_list: list,
+        worker_version: bool = None,
+    ):
+        """
+        Create multiple metadata on an existing element.
+        This method does not support cache.
+
+        :param element Element: The element to create multiple metadata on.
+        :param metadata_list List(MetaDataBulkItem): The list of MetaDataBulkItem.
+        """
+        assert element and isinstance(
+            element, Element
+        ), "element shouldn't be null and should be of type Element"
+
+        assert metadata_list and isinstance(
+            metadata_list, list
+        ), "type shouldn't be null and should be of type list of MetaType"
+
+        metadatabulk = self.request(
+            "CreateMetaDataBulk",
+            id=element.id,
+            body={"worker_version": worker_version, "metadata_list": metadata_list},
+        )
+
+        return metadatabulk
+
     def list_metadata(self, element: Element):
         """
-        List all metadata linked to an element
-        This method does not support cache
+        List all metadata linked to an element.
+        This method does not support cache..
 
         :param element Element: The element to list metadata on.
         """
diff --git a/tests/test_elements_worker/test_metadata.py b/tests/test_elements_worker/test_metadata.py
index 3aa74f96..4e414809 100644
--- a/tests/test_elements_worker/test_metadata.py
+++ b/tests/test_elements_worker/test_metadata.py
@@ -198,6 +198,24 @@ def test_create_metadata(responses, mock_elements_worker):
     assert metadata_id == "12345678-1234-1234-1234-123456789123"
 
 
+def test_create_metadatabulk(responses, fake_dummy_worker):
+    element = Element({"id": "element_id"})
+    metadata_list = [MetaType("text"), "fake_name", "fake_value"]
+    worker_version = "worker_version"
+    fake_dummy_worker.api_client.add_response(
+        "CreateMetaDataBulk",
+        id=element.id,
+        response={"worker_version": "worker_version", "metadata_list": metadata_list},
+        body={"worker_version": "worker_version", "metadata_list": metadata_list},
+    )
+    assert fake_dummy_worker.create_metadatabulk(
+        element, metadata_list, worker_version
+    ) == {"worker_version": "worker_version", "metadata_list": metadata_list}
+
+    assert len(fake_dummy_worker.api_client.history) == 1
+    assert len(fake_dummy_worker.api_client.responses) == 0
+
+
 def test_list_metadata(fake_dummy_worker):
     element = Element({"id": "element_id"})
     fake_dummy_worker.api_client.add_response(
-- 
GitLab