Skip to content
Snippets Groups Projects
Verified Commit 46a925bd authored by NolanB's avatar NolanB Committed by Yoann Schneider
Browse files

Add a list_corpus_entities() method to entity.py

parent e61f82d6
No related branches found
No related tags found
1 merge request!206Helper for ListCorpusEntities
This commit is part of merge request !206. Comments created here will be created in the context of that merge request.
......@@ -197,37 +197,32 @@ class EntityMixin(object):
def list_corpus_entities(
self,
corpus: Corpus,
name: str = None,
parent: str or Element = None,
name: str,
parent: str,
):
"""
List all entities in a corpus
This method does not support cache
:param corpus Corpus: The corpus that contains the entities to list.
:param name str: For filter entities by part of their name (case-insensitive)
:param name str: uuid for filter entities by part of their name (case-insensitive)
:param parent str: uuid for restrict entities to those linked to all transcriptions of an element and all its descendants. Note that links to metadata are ignored.
"""
query_params = {}
assert corpus and isinstance(
corpus, Corpus
), "corpus shouldn't be null and should be a Corpus"
assert name and isinstance(
name, str
), "name shouldn't be null and should be of type str"
assert parent and isinstance(
parent, str
), "parent shouldn't be null and should be of type str"
if name is not None:
assert name and isinstance(name, str), "name should be of type str"
query_params["name"] = name
if parent is not None:
assert (
parent
and isinstance(parent, str)
or parent
and isinstance(parent, Element)
), "parent should be of type str or Element"
query_params["parent"] = parent
if type(parent) == Element:
query_params["parent"] = parent.id
query_params["name"] = name
query_params["parent"] = parent
return self.api_client.paginate(
"ListCorpusEntities", id=corpus.id, **query_params
......
......@@ -656,6 +656,7 @@ def test_list_transcription_entities(fake_dummy_worker):
assert len(fake_dummy_worker.api_client.responses) == 0
<<<<<<< HEAD
@pytest.mark.parametrize(
"name, parent",
[
......@@ -686,5 +687,22 @@ def test_list_corpus_entities(fake_dummy_worker, name, parent):
assert fake_dummy_worker.list_corpus_entities(corpus, **query_params) == {
"id": "fake_entity_id"
}
=======
def test_list_corpus_entities(fake_dummy_worker):
corpus = Corpus({"id": "fake_corpus_id"})
name = "fake_name"
parent = "fake_parent"
fake_dummy_worker.api_client.add_response(
"ListCorpusEntities",
id=corpus.id,
name=name,
parent=parent,
response={"id": "fake_entity_id"},
)
assert fake_dummy_worker.list_corpus_entities(corpus, name, parent) == {
"id": "fake_entity_id"
}
>>>>>>> fb7d0b7... Add a list_corpus_entities() method to entity.py
assert len(fake_dummy_worker.api_client.history) == 1
assert len(fake_dummy_worker.api_client.responses) == 0
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