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

Return created instance ID in helpers

parent e8e9579a
No related branches found
No related tags found
1 merge request!18Return created instance ID in helpers
Pipeline #77941 passed
......@@ -187,6 +187,7 @@ class ElementsWorker(BaseWorker):
def create_sub_element(self, element, type, name, polygon):
"""
Create a child element on the given element through API
Return the ID of the created sub element
"""
assert element and isinstance(
element, Element
......@@ -208,7 +209,7 @@ class ElementsWorker(BaseWorker):
isinstance(coord, (int, float)) for point in polygon for coord in point
), "polygon points should be lists of two numbers"
self.api_client.request(
sub_element = self.api_client.request(
"CreateElement",
body={
"type": type,
......@@ -222,6 +223,8 @@ class ElementsWorker(BaseWorker):
)
self.report.add_element(element.id, type)
return sub_element["id"]
def create_transcription(self, element, text, type, score):
"""
Create a transcription on the given element through API
......@@ -285,6 +288,7 @@ class ElementsWorker(BaseWorker):
def create_entity(self, element, name, type, corpus, metas=None, validated=None):
"""
Create an entity on the given corpus through API
Return the ID of the created entity
"""
assert element and isinstance(
element, Element
......@@ -315,3 +319,5 @@ class ElementsWorker(BaseWorker):
},
)
self.report.add_entity(element.id, entity["id"], type.value, name)
return entity["id"]
......@@ -365,9 +365,10 @@ def test_create_sub_element(responses):
responses.POST,
"https://arkindex.teklia.com/api/v1/elements/create/",
status=200,
json={"id": "12345678-1234-1234-1234-123456789123"},
)
worker.create_sub_element(
sub_element_id = worker.create_sub_element(
element=elt,
type="something",
name="0",
......@@ -388,6 +389,7 @@ def test_create_sub_element(responses):
"parent": "12341234-1234-1234-1234-123412341234",
"worker_version": "12341234-1234-1234-1234-123412341234",
}
assert sub_element_id == "12345678-1234-1234-1234-123456789123"
def test_create_transcription_wrong_element():
......@@ -855,7 +857,7 @@ def test_create_entity(responses):
json={"id": "12345678-1234-1234-1234-123456789123"},
)
worker.create_entity(
entity_id = worker.create_entity(
element=elt,
name="Bob Bob",
type=EntityType.Person,
......@@ -874,3 +876,4 @@ def test_create_entity(responses):
"corpus": "12341234-1234-1234-1234-123412341234",
"worker_version": "12341234-1234-1234-1234-123412341234",
}
assert entity_id == "12345678-1234-1234-1234-123456789123"
......@@ -8,4 +8,4 @@ line_length = 88
default_section=FIRSTPARTY
known_first_party =
known_third_party = arkindex_worker,setuptools
known_third_party = arkindex_worker,pytest,setuptools
......@@ -8,4 +8,5 @@ commands =
deps =
pytest
pytest-responses
-rrequirements.txt
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