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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ test = [
"pytest>=8.4.1",
"pytest-cov>=6.2.1",
"pytest-emoji>=0.2.0",
"pytest-httpx>=0.30.0",
"pytest-md>=0.2.0",
]
doc = [
Expand Down
23 changes: 22 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def mock_client(base_url):


@pytest.fixture
def mock_authenticated_client(base_url, api_token):
def templafy_client(base_url, api_token):
"""Mock authenticated client for testing."""
return AuthenticatedClient(base_url=base_url, token=api_token)

Expand Down Expand Up @@ -90,3 +90,24 @@ def mock_library_data():
"is_active": True,
},
]


@pytest.fixture
def sample_document():
"""Sample document data for testing."""
return {
"id": "doc1",
"name": "Test Document 1",
"description": "A test document",
"template_type": "word",
"library_id": "lib1",
"folderId": "folder1",
"tags": ["test", "document"],
"fileSize": 1024,
"checksum": "abc123",
"fileExtension": "docx",
"downloadUrl": "https://example.com/download/doc1.docx",
"navigationPath": "/folder1/doc1.docx",
"modifiedAt": "2023-01-01T00:00:00Z",
"assetState": "ready",
}
27 changes: 27 additions & 0 deletions tests/templafy/api/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest


@pytest.fixture
def sample_library_data():
"""Sample library data for testing get_libraries."""
return [
{
"id": 1,
"name": "Test Library",
"libraryType": "documents",
"spaceId": 1,
"rootFolderId": 1,
}
]


@pytest.fixture
def sample_library_details_data():
"""Sample library details data for testing get_libraries_space_id_library_type."""
return {
"id": 1,
"name": "Test Library Details",
"libraryType": "documents",
"spaceId": 1,
"rootFolderId": 1,
}
27 changes: 27 additions & 0 deletions tests/templafy/api/documents/test_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from io import BytesIO

from httpx import codes

from templafy.api.documents import (
post_libraries_space_id_documents_folders_folder_id_assets as api,
)
from templafy.models.post_libraries_space_id_documents_folders_folder_id_assets_body import (
PostLibrariesSpaceIdDocumentsFoldersFolderIdAssetsBody,
)
from templafy.types import File


def test_create_document_returns_document(httpx_mock, templafy_client):
# Create mock file
mock_file = File(
payload=BytesIO(b"mock file content"),
file_name="test.docx",
mime_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
)
body = PostLibrariesSpaceIdDocumentsFoldersFolderIdAssetsBody(file=mock_file)

httpx_mock.add_response(status_code=codes.CREATED, json=123)

result = api.sync(space_id=1, folder_id=1, client=templafy_client, body=body)

assert result == 123
13 changes: 13 additions & 0 deletions tests/templafy/api/documents/test_delete_by_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from httpx import codes

from templafy.api.documents import (
delete_libraries_space_id_documents_assets_asset_id as api,
)


def test_delete_document_by_id_returns_none_on_204(httpx_mock, templafy_client):
httpx_mock.add_response(status_code=codes.NO_CONTENT)

result = api.sync(space_id=1, asset_id=123, client=templafy_client)

assert result is None
23 changes: 23 additions & 0 deletions tests/templafy/api/documents/test_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from httpx import codes

from templafy.api.documents import (
post_libraries_space_id_documents_assets_asset_id_generate as api,
)
from templafy.models.generate_file_request import GenerateFileRequest


def test_generate_document_returns_expected_payload(httpx_mock, templafy_client):
body = GenerateFileRequest(email="test@example.com")
payload = {
"downloadUrl": "https://example.com/generated.docx",
"fileSize": 1024,
"checksum": "abc123",
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"fileExtension": "docx",
}
httpx_mock.add_response(status_code=codes.OK, json=payload)

result = api.sync(space_id=1, asset_id=123, client=templafy_client, body=body)

assert result is not None
assert result.download_url == payload["downloadUrl"]
17 changes: 17 additions & 0 deletions tests/templafy/api/documents/test_get_by_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from httpx import codes

from templafy.api.documents import (
get_libraries_space_id_documents_assets_asset_id as api,
)


def test_get_document_by_id_returns_parsed_list(
httpx_mock, templafy_client, sample_document
):
# stub httpx response
httpx_mock.add_response(status_code=codes.OK, json=[sample_document])

result = api.sync(space_id=1, asset_id=123, client=templafy_client)

assert isinstance(result, list)
assert result[0].id == sample_document["id"]
16 changes: 16 additions & 0 deletions tests/templafy/api/documents/test_list_in_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from httpx import codes

from templafy.api.documents import (
get_libraries_space_id_documents_folders_folder_id_assets as api,
)


def test_list_documents_in_folder_returns_document_list(
httpx_mock, templafy_client, sample_document
):
httpx_mock.add_response(status_code=codes.OK, json=[sample_document])

result = api.sync(space_id=1, folder_id=1, client=templafy_client)

assert isinstance(result, list)
assert result[0].id == sample_document["id"]
17 changes: 17 additions & 0 deletions tests/templafy/api/documents/test_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from httpx import codes

from templafy.api.documents import (
patch_libraries_space_id_documents_assets_asset_id as api,
)
from templafy.models.patch_libraries_space_id_documents_assets_asset_id_body import (
PatchLibrariesSpaceIdDocumentsAssetsAssetIdBody,
)


def test_update_document_returns_none_on_204(httpx_mock, templafy_client):
httpx_mock.add_response(status_code=codes.NO_CONTENT)

body = PatchLibrariesSpaceIdDocumentsAssetsAssetIdBody()
result = api.sync(space_id=1, asset_id=123, client=templafy_client, body=body)

assert result is None
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from httpx import codes

from templafy.api.libraries import get_libraries_space_id_library_type
from templafy.models.library_type import LibraryType


def test_get_library_by_space_and_type_returns_details(
httpx_mock, templafy_client, sample_library_details_data
):
# Mock httpx response
httpx_mock.add_response(status_code=codes.OK, json=sample_library_details_data)

result = get_libraries_space_id_library_type.sync(
space_id=1, library_type=LibraryType.DOCUMENTS, client=templafy_client
)

assert result is not None
assert result.root_folder_id == sample_library_details_data["rootFolderId"]
12 changes: 12 additions & 0 deletions tests/templafy/api/libraries/test_libraries_get_libraries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from httpx import codes

from templafy.api.libraries import get_libraries


def test_get_libraries_returns_list(httpx_mock, templafy_client, sample_library_data):
# Mock httpx response
httpx_mock.add_response(status_code=codes.OK, json=sample_library_data)

result = get_libraries.sync(client=templafy_client)

assert isinstance(result, list)
2 changes: 0 additions & 2 deletions tests/templafy/test_client.py

This file was deleted.

17 changes: 16 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading