From 0d986c15744b201daed676f94d8a63e60ce1598a Mon Sep 17 00:00:00 2001 From: Bara Molova Date: Tue, 6 Feb 2024 11:02:11 +0100 Subject: [PATCH] feat: add new create_new_annotation method --- rossum_api/elis_api_client.py | 6 +++++ rossum_api/elis_api_client_sync.py | 4 +++ tests/elis_api_client/test_annotations.py | 30 +++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/rossum_api/elis_api_client.py b/rossum_api/elis_api_client.py index 17f0182..9f2065b 100644 --- a/rossum_api/elis_api_client.py +++ b/rossum_api/elis_api_client.py @@ -353,6 +353,12 @@ async def confirm_annotation(self, annotation_id: int) -> None: "POST", f"{Resource.Annotation.value}/{annotation_id}/confirm" ) + async def create_new_annotation(self, data: dict[str, Any]) -> Annotation: + """https://elis.rossum.ai/api/docs/#create-an-annotation""" + annotation = await self._http_client.create(Resource.Annotation, data) + + return self._deserializer(Resource.Annotation, annotation) + # ##### DOCUMENTS ##### async def retrieve_document_content(self, document_id: int) -> bytes: """https://elis.rossum.ai/api/docs/#document-content""" diff --git a/rossum_api/elis_api_client_sync.py b/rossum_api/elis_api_client_sync.py index 54d3ec3..26a0739 100644 --- a/rossum_api/elis_api_client_sync.py +++ b/rossum_api/elis_api_client_sync.py @@ -315,6 +315,10 @@ def confirm_annotation(self, annotation_id: int) -> None: """https://elis.rossum.ai/api/docs/#confirm-annotation""" self.event_loop.run_until_complete(self.elis_api_client.confirm_annotation(annotation_id)) + def create_new_annotation(self, data: dict[str, Any]) -> Annotation: + """https://elis.rossum.ai/api/docs/#create-an-annotation""" + return self.event_loop.run_until_complete(self.elis_api_client.create_new_annotation(data)) + # ##### DOCUMENTS ##### def retrieve_document_content(self, document_id: int) -> bytes: """https://elis.rossum.ai/api/docs/#document-content""" diff --git a/tests/elis_api_client/test_annotations.py b/tests/elis_api_client/test_annotations.py index ef8084c..2508c33 100644 --- a/tests/elis_api_client/test_annotations.py +++ b/tests/elis_api_client/test_annotations.py @@ -344,6 +344,21 @@ async def test_confirm_annotation(self, elis_client, dummy_annotation): await client.confirm_annotation(aid) http_client.request_json.assert_called_with("POST", f"annotations/{aid}/confirm") + async def test_create_new_annotation(self, elis_client, dummy_annotation): + client, http_client = elis_client + http_client.create.return_value = dummy_annotation + + data = { + "status": "created", + "document": dummy_annotation["document"], + "queue": dummy_annotation["queue"], + } + annotation = await client.create_new_annotation(data) + + assert annotation == Annotation(**dummy_annotation) + + http_client.create.assert_called_with(Resource.Annotation, data) + class TestAnnotationsSync: def test_list_all_annotations(self, elis_client_sync, dummy_annotation, mock_generator): @@ -571,3 +586,18 @@ def test_confirm_annotation(self, elis_client_sync, dummy_annotation): client.confirm_annotation(aid) http_client.request_json.assert_called_with("POST", f"annotations/{aid}/confirm") + + def test_create_new_annotation(self, elis_client_sync, dummy_annotation): + client, http_client = elis_client_sync + http_client.create.return_value = dummy_annotation + + data = { + "status": "created", + "document": dummy_annotation["document"], + "queue": dummy_annotation["queue"], + } + annotation = client.create_new_annotation(data) + + assert annotation == Annotation(**dummy_annotation) + + http_client.create.assert_called_with(Resource.Annotation, data)