Skip to content
Snippets Groups Projects
Commit 6890ca2a authored by Eva Bardou's avatar Eva Bardou Committed by Bastien Abadie
Browse files

Retrieve ARKINDEX_CORPUS_ID in create_entity when corpus is None

parent 2f2e425e
No related branches found
No related tags found
1 merge request!93Retrieve ARKINDEX_CORPUS_ID in create_entity when corpus is None
Pipeline #78481 passed
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
from enum import Enum from enum import Enum
from arkindex_worker import logger from arkindex_worker import logger
...@@ -24,6 +23,9 @@ class EntityMixin(object): ...@@ -24,6 +23,9 @@ class EntityMixin(object):
Create an entity on the given corpus through API Create an entity on the given corpus through API
Return the ID of the created entity Return the ID of the created entity
""" """
if corpus is None:
corpus = os.environ.get("ARKINDEX_CORPUS_ID")
assert element and isinstance( assert element and isinstance(
element, (Element, CachedElement) element, (Element, CachedElement)
), "element shouldn't be null and should be an Element or CachedElement" ), "element shouldn't be null and should be an Element or CachedElement"
......
...@@ -87,9 +87,23 @@ def test_create_entity_wrong_type(mock_elements_worker): ...@@ -87,9 +87,23 @@ def test_create_entity_wrong_type(mock_elements_worker):
assert str(e.value) == "type shouldn't be null and should be of type EntityType" assert str(e.value) == "type shouldn't be null and should be of type EntityType"
def test_create_entity_wrong_corpus(mock_elements_worker): def test_create_entity_wrong_corpus(monkeypatch, mock_elements_worker):
elt = Element({"id": "12341234-1234-1234-1234-123412341234"}) elt = Element({"id": "12341234-1234-1234-1234-123412341234"})
# Triggering an error on metas param, giving corpus=None should work since
# ARKINDEX_CORPUS_ID environment variable is set on mock_elements_worker
with pytest.raises(AssertionError) as e:
mock_elements_worker.create_entity(
element=elt,
name="Bob Bob",
type=EntityType.Person,
corpus=None,
metas="wrong metas",
)
assert str(e.value) == "metas should be of type dict"
# Removing ARKINDEX_CORPUS_ID environment variable should give an error when corpus=None
monkeypatch.delenv("ARKINDEX_CORPUS_ID")
with pytest.raises(AssertionError) as e: with pytest.raises(AssertionError) as e:
mock_elements_worker.create_entity( mock_elements_worker.create_entity(
element=elt, element=elt,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment