Skip to content

Commit

Permalink
feat: add new create_new_annotation method
Browse files Browse the repository at this point in the history
  • Loading branch information
bara-m committed Feb 6, 2024
1 parent 62528c4 commit 0d986c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rossum_api/elis_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
4 changes: 4 additions & 0 deletions rossum_api/elis_api_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
30 changes: 30 additions & 0 deletions tests/elis_api_client/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 0d986c1

Please sign in to comment.