Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.4.2 - 2025-08-14

- Do not discard documents based on their content type

## Version 0.2.0 - 2025-07-02

- Updated access token generation code to work with new IdP
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "cradl"
version = "0.4.1"
version = "0.4.2"
description = "Python SDK for Cradl"
authors = [{ name = "Cradl", email = "[email protected]" }]
readme = "README.md"
Expand Down
7 changes: 6 additions & 1 deletion src/cradl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,12 @@ def create_document(
}

document = self._make_request(requests.post, '/documents', body=dictstrip(body))
self._make_fileserver_request(requests.put, document['fileUrl'], content=content_bytes)
try:
self._make_fileserver_request(requests.put, document['fileUrl'], content=content_bytes)
except Exception as e:
self.delete_document(document['documentId'])
raise e

return document

def list_documents(
Expand Down
2 changes: 0 additions & 2 deletions src/cradl/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

def _guess_content_type(raw):
guessed_type = filetype.guess(raw)
assert guessed_type, 'Could not determine content type of document. ' \
'Please provide it by specifying content_type'
return guessed_type.mime


Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ def content():
Yields a random JPEG bytestring with a length 2E4
"""
yield b'\xFF\xD8\xFF\xEE' + urandom(int(2E4))


@pytest.fixture(scope='session')
def pdf_content():
yield 'HTTP/1.0 200 OK%PDF-1.4 %½¾¼µ %%EOF'.encode()
9 changes: 7 additions & 2 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
pytestmark = pytest.mark.integration


@pytest.mark.parametrize('metadata', [util.metadata(), None])
@pytest.mark.parametrize(('metadata', 'image'), [
(util.metadata(), True),
(None, False),
])
def test_create_document(
monkeypatch,
static_client: Client,
content,
image,
metadata,
pdf_content,
):
consent_id = service.create_consent_id()
post_documents_response = static_client.create_document(
content,
content if image else pdf_content,
consent_id=consent_id,
metadata=metadata,
)
Expand Down
Loading