Skip to content
Snippets Groups Projects
Commit 654c5cda 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 #78484 passed
# -*- coding: utf-8 -*-
import os
from enum import Enum
from arkindex_worker import logger
......@@ -19,11 +18,16 @@ class EntityType(Enum):
class EntityMixin(object):
def create_entity(self, element, name, type, corpus, metas=None, validated=None):
def create_entity(
self, element, name, type, corpus=None, metas=None, validated=None
):
"""
Create an entity on the given corpus through API
Return the ID of the created entity
"""
if corpus is None:
corpus = os.environ.get("ARKINDEX_CORPUS_ID")
assert element and isinstance(
element, (Element, CachedElement)
), "element shouldn't be null and should be an Element or CachedElement"
......
......@@ -87,9 +87,22 @@ def test_create_entity_wrong_type(mock_elements_worker):
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"})
# Triggering an error on metas param, not giving corpus 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,
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:
mock_elements_worker.create_entity(
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