diff --git a/arkindex_worker/worker.py b/arkindex_worker/worker.py index 4c56bf1ef681e6b032769af5089a86b3c93f0ae1..6c667efa34e3f932ecde08d7bd29a7efee8da35d 100644 --- a/arkindex_worker/worker.py +++ b/arkindex_worker/worker.py @@ -889,12 +889,13 @@ class ElementsWorker(BaseWorker): ), "worker_version should be of type str" query_params["worker_version"] = worker_version - # Checking that we only have query_params handled by the cache - if self.use_cache and set(query_params.keys()) <= { - "name", - "type", - "worker_version", - }: + if self.use_cache: + # Checking that we only received query_params handled by the cache + assert set(query_params.keys()) <= { + "name", + "type", + "worker_version", + }, "When using the local cache, you can only filter by 'name', 'type' and/or 'worker_version'" parent_id_hex = convert_str_uuid_to_hex(element.id) name_condition = f" AND name LIKE '%{name}%'" if name else "" type_condition = f" AND type='{type}'" if type else "" diff --git a/tests/test_elements_worker/test_elements.py b/tests/test_elements_worker/test_elements.py index c79a106a6548f4a2dfbf5bec8f945dd53310b55e..76e62267f5a650fb6fe9eae41eef18487c512f26 100644 --- a/tests/test_elements_worker/test_elements.py +++ b/tests/test_elements_worker/test_elements.py @@ -941,51 +941,18 @@ def test_list_element_children(responses, mock_elements_worker): def test_list_element_children_with_cache_unhandled_param( - responses, mock_elements_worker_with_cache + mock_elements_worker_with_cache, ): - """ - Calls list_elements_children on a worker using the cache. - The cache doesn't contain any information about an element corpus and with_corpus query param is set to True. - The list_elements_children function will call the API (instead of the cache) to use the with_corpus param. - """ elt = Element({"id": "12341234-1234-1234-1234-123412341234"}) - expected_children = [ - { - "id": "0000", - "type": "page", - "name": "Test", - "corpus": {}, - "thumbnail_url": None, - "zone": {}, - "best_classes": None, - "has_children": None, - "worker_version_id": None, - } - ] - responses.add( - responses.GET, - "http://testserver/api/v1/elements/12341234-1234-1234-1234-123412341234/children/?with_corpus=True", - status=200, - json={ - "count": 1, - "next": None, - "results": expected_children, - }, - ) - for idx, child in enumerate( + with pytest.raises(AssertionError) as e: mock_elements_worker_with_cache.list_element_children( element=elt, with_corpus=True ) - ): - assert child == expected_children[idx] - - assert len(responses.calls) == 3 - assert [call.request.url for call in responses.calls] == [ - "http://testserver/api/v1/user/", - "http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/", - "http://testserver/api/v1/elements/12341234-1234-1234-1234-123412341234/children/?with_corpus=True", - ] + assert ( + str(e.value) + == "When using the local cache, you can only filter by 'name', 'type' and/or 'worker_version'" + ) def test_list_element_children_with_cache(responses, mock_elements_worker_with_cache):