Skip to content

Commit

Permalink
feat: add new retrieve_document_content method
Browse files Browse the repository at this point in the history
  • Loading branch information
bara-m committed Feb 5, 2024
1 parent 45dfc8a commit 80ca28e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
5 changes: 5 additions & 0 deletions rossum_api/elis_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ async def confirm_annotation(self, annotation_id: int) -> None:
"POST", f"{Resource.Annotation.value}/{annotation_id}/confirm"
)

# ##### DOCUMENTS #####
async def retrieve_document_content(self, document_id: str) -> bytes:
"""https://elis.rossum.ai/api/docs/#document-content"""
return await self._http_client.request("GET", url=f"documents/{document_id}/content")

# ##### WORKSPACES #####
async def list_all_workspaces(
self,
Expand Down
9 changes: 8 additions & 1 deletion rossum_api/elis_api_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def retrieve_organization(
)

def retrieve_own_organization(self) -> Organization:
"""Retrieve organization of currently logged in user."""
"""Retrive organization of currently logged in user."""
return self.event_loop.run_until_complete(self.elis_api_client.retrieve_own_organization())

# ##### SCHEMAS #####
Expand Down Expand Up @@ -314,6 +314,13 @@ 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))

# ##### DOCUMENTS #####
def retrieve_document_content(self, document_id: str) -> bytes:
"""https://elis.rossum.ai/api/docs/#document-content"""
return self.event_loop.run_until_complete(
self.elis_api_client.retrieve_document_content(document_id)
)

# ##### WORKSPACES #####
def list_all_workspaces(
self,
Expand Down
36 changes: 36 additions & 0 deletions tests/elis_api_client/test_documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

import pytest


@pytest.mark.asyncio
class TestQueues:
async def test_retrieve_document_content(self, elis_client):
client, http_client = elis_client

with open("tests/data/sample_invoice.pdf", "rb") as f:
http_client.request.return_value = f.read()

document_id = 123
result = await client.retrieve_document_content(document_id=document_id)

http_client.request.assert_called_with("GET", url=f"documents/{document_id}/content")

with open("tests/data/sample_invoice.pdf", "rb") as expected_file:
assert result == expected_file.read()


class TestDocumentsSync:
def test_retrieve_document_content(self, elis_client_sync):
client, http_client = elis_client_sync

with open("tests/data/sample_invoice.pdf", "rb") as f:
http_client.request.return_value = f.read()

document_id = 123
result = client.retrieve_document_content(document_id=document_id)

http_client.request.assert_called_with("GET", url=f"documents/{document_id}/content")

with open("tests/data/sample_invoice.pdf", "rb") as expected_file:
assert result == expected_file.read()

0 comments on commit 80ca28e

Please sign in to comment.