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 6, 2024
1 parent 45dfc8a commit 4057e9c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions rossum_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Resource(Enum):
Annotation = "annotations"
Auth = "auth"
Connector = "connectors"
Document = "documents"
Group = "groups"
Hook = "hooks"
Inbox = "inboxes"
Expand Down
8 changes: 8 additions & 0 deletions rossum_api/elis_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ 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: int) -> bytes:
"""https://elis.rossum.ai/api/docs/#document-content"""
document_content = await self._http_client.request(
"GET", url=f"{Resource.Document.value}/{document_id}/content"
)
return document_content.content

# ##### WORKSPACES #####
async def list_all_workspaces(
self,
Expand Down
7 changes: 7 additions & 0 deletions rossum_api/elis_api_client_sync.py
Original file line number Diff line number Diff line change
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: int) -> 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
41 changes: 41 additions & 0 deletions tests/elis_api_client/test_documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations

import httpx
import pytest

from rossum_api.api_client import Resource


@pytest.fixture
def file_data() -> bytes:
with open("tests/data/sample_invoice.pdf", "rb") as f:
return f.read()


@pytest.mark.asyncio
class TestDocuments:
async def test_retrieve_document_content(self, elis_client, file_data):
client, http_client = elis_client
http_client.request.return_value = httpx.Response(status_code=200, content=file_data)

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

http_client.request.assert_called_with(
"GET", url=f"{Resource.Document.value}/{document_id}/content"
)
assert result == file_data


class TestDocumentsSync:
def test_retrieve_document_content(self, elis_client_sync, file_data):
client, http_client = elis_client_sync
http_client.request.return_value = httpx.Response(status_code=200, content=file_data)

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

http_client.request.assert_called_with(
"GET", url=f"{Resource.Document.value}/{document_id}/content"
)
assert result == file_data

0 comments on commit 4057e9c

Please sign in to comment.