From f2530289ec507dab3593b4397f9cfe032f1cc771 Mon Sep 17 00:00:00 2001
From: Eva Bardou <ebardou@teklia.com>
Date: Thu, 8 Apr 2021 16:05:26 +0200
Subject: [PATCH] Support giving a CachedElement in helper functions using the
 local cache

---
 arkindex_worker/worker/element.py                 |  4 ++--
 arkindex_worker/worker/transcription.py           |  4 ++--
 tests/test_elements_worker/test_elements.py       | 10 ++++++++--
 tests/test_elements_worker/test_transcriptions.py | 10 ++++++++--
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/arkindex_worker/worker/element.py b/arkindex_worker/worker/element.py
index ecedb26a..b25e8c51 100644
--- a/arkindex_worker/worker/element.py
+++ b/arkindex_worker/worker/element.py
@@ -172,8 +172,8 @@ class ElementMixin(object):
         List children of an element
         """
         assert element and isinstance(
-            element, Element
-        ), "element shouldn't be null and should be of type Element"
+            element, (Element, CachedElement)
+        ), "element shouldn't be null and should be an Element or CachedElement"
         query_params = {}
         if best_class is not None:
             assert isinstance(best_class, str) or isinstance(
diff --git a/arkindex_worker/worker/transcription.py b/arkindex_worker/worker/transcription.py
index 23f1088e..2dd27a60 100644
--- a/arkindex_worker/worker/transcription.py
+++ b/arkindex_worker/worker/transcription.py
@@ -233,8 +233,8 @@ class TranscriptionMixin(object):
         List transcriptions on an element
         """
         assert element and isinstance(
-            element, Element
-        ), "element shouldn't be null and should be of type Element"
+            element, (Element, CachedElement)
+        ), "element shouldn't be null and should be an Element or CachedElement"
         query_params = {}
         if element_type:
             assert isinstance(element_type, str), "element_type should be of type str"
diff --git a/tests/test_elements_worker/test_elements.py b/tests/test_elements_worker/test_elements.py
index a903a74d..0c790b6a 100644
--- a/tests/test_elements_worker/test_elements.py
+++ b/tests/test_elements_worker/test_elements.py
@@ -900,11 +900,17 @@ def test_create_elements_integrity_error(
 def test_list_element_children_wrong_element(mock_elements_worker):
     with pytest.raises(AssertionError) as e:
         mock_elements_worker.list_element_children(element=None)
-    assert str(e.value) == "element shouldn't be null and should be of type Element"
+    assert (
+        str(e.value)
+        == "element shouldn't be null and should be an Element or CachedElement"
+    )
 
     with pytest.raises(AssertionError) as e:
         mock_elements_worker.list_element_children(element="not element type")
-    assert str(e.value) == "element shouldn't be null and should be of type Element"
+    assert (
+        str(e.value)
+        == "element shouldn't be null and should be an Element or CachedElement"
+    )
 
 
 def test_list_element_children_wrong_best_class(mock_elements_worker):
diff --git a/tests/test_elements_worker/test_transcriptions.py b/tests/test_elements_worker/test_transcriptions.py
index 20042876..de464ac8 100644
--- a/tests/test_elements_worker/test_transcriptions.py
+++ b/tests/test_elements_worker/test_transcriptions.py
@@ -1041,11 +1041,17 @@ def test_create_element_transcriptions(responses, mock_elements_worker_with_cach
 def test_list_transcriptions_wrong_element(mock_elements_worker):
     with pytest.raises(AssertionError) as e:
         mock_elements_worker.list_transcriptions(element=None)
-    assert str(e.value) == "element shouldn't be null and should be of type Element"
+    assert (
+        str(e.value)
+        == "element shouldn't be null and should be an Element or CachedElement"
+    )
 
     with pytest.raises(AssertionError) as e:
         mock_elements_worker.list_transcriptions(element="not element type")
-    assert str(e.value) == "element shouldn't be null and should be of type Element"
+    assert (
+        str(e.value)
+        == "element shouldn't be null and should be an Element or CachedElement"
+    )
 
 
 def test_list_transcriptions_wrong_element_type(mock_elements_worker):
-- 
GitLab