Skip to content

Commit 4e214f6

Browse files
tests: Add PDF/A lowercase normalization coverage
1 parent 619a011 commit 4e214f6

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

tests/test_convert_to_pdfa.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import json
4+
from typing import Any, cast
45

56
import httpx
67
import pytest
@@ -210,6 +211,44 @@ def handler(request: httpx.Request) -> httpx.Response:
210211
assert timeout_value == pytest.approx(0.33)
211212

212213

214+
def test_convert_to_pdfa_normalizes_lowercase_output_type(
215+
monkeypatch: pytest.MonkeyPatch,
216+
) -> None:
217+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
218+
input_file = make_pdf_file(PdfRestFileID.generate(1))
219+
output_id = str(PdfRestFileID.generate())
220+
221+
def handler(request: httpx.Request) -> httpx.Response:
222+
if request.method == "POST" and request.url.path == "/pdfa":
223+
payload = json.loads(request.content.decode("utf-8"))
224+
assert payload["output_type"] == "PDF/A-2b"
225+
assert payload["id"] == str(input_file.id)
226+
return httpx.Response(
227+
200,
228+
json={"inputId": [input_file.id], "outputId": [output_id]},
229+
)
230+
if request.method == "GET" and request.url.path == f"/resource/{output_id}":
231+
return httpx.Response(
232+
200,
233+
json=build_file_info_payload(
234+
output_id, "lowercase.pdf", "application/pdf"
235+
),
236+
)
237+
msg = f"Unexpected request {request.method} {request.url}"
238+
raise AssertionError(msg)
239+
240+
transport = httpx.MockTransport(handler)
241+
with PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client:
242+
response = client.convert_to_pdfa(
243+
input_file,
244+
output_type=cast(Any, "pdf/a-2b"),
245+
)
246+
247+
assert isinstance(response, PdfRestFileBasedResponse)
248+
assert response.output_file.name == "lowercase.pdf"
249+
assert str(response.input_id) == str(input_file.id)
250+
251+
213252
@pytest.mark.asyncio
214253
async def test_async_convert_to_pdfa_request_customization(
215254
monkeypatch: pytest.MonkeyPatch,
@@ -272,6 +311,45 @@ def handler(request: httpx.Request) -> httpx.Response:
272311
assert timeout_value == pytest.approx(0.72)
273312

274313

314+
@pytest.mark.asyncio
315+
async def test_async_convert_to_pdfa_normalizes_lowercase_output_type(
316+
monkeypatch: pytest.MonkeyPatch,
317+
) -> None:
318+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
319+
input_file = make_pdf_file(PdfRestFileID.generate(2))
320+
output_id = str(PdfRestFileID.generate())
321+
322+
def handler(request: httpx.Request) -> httpx.Response:
323+
if request.method == "POST" and request.url.path == "/pdfa":
324+
payload = json.loads(request.content.decode("utf-8"))
325+
assert payload["output_type"] == "PDF/A-2b"
326+
assert payload["id"] == str(input_file.id)
327+
return httpx.Response(
328+
200,
329+
json={"inputId": [input_file.id], "outputId": [output_id]},
330+
)
331+
if request.method == "GET" and request.url.path == f"/resource/{output_id}":
332+
return httpx.Response(
333+
200,
334+
json=build_file_info_payload(
335+
output_id, "async-lowercase.pdf", "application/pdf"
336+
),
337+
)
338+
msg = f"Unexpected request {request.method} {request.url}"
339+
raise AssertionError(msg)
340+
341+
transport = httpx.MockTransport(handler)
342+
async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client:
343+
response = await client.convert_to_pdfa(
344+
input_file,
345+
output_type=cast(Any, "pdf/a-2b"),
346+
)
347+
348+
assert isinstance(response, PdfRestFileBasedResponse)
349+
assert response.output_file.name == "async-lowercase.pdf"
350+
assert str(response.input_id) == str(input_file.id)
351+
352+
275353
def test_convert_to_pdfa_validation(monkeypatch: pytest.MonkeyPatch) -> None:
276354
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
277355
pdf_file = make_pdf_file(PdfRestFileID.generate(1))

0 commit comments

Comments
 (0)