Skip to content

Commit 432ccfa

Browse files
Add missing unit tests
Resolve discrepancies in unit tests between sync and async Assisted-by: Codex
1 parent e003088 commit 432ccfa

4 files changed

Lines changed: 90 additions & 8 deletions

File tree

tests/test_convert_to_jpeg.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,16 @@ def handler(_: httpx.Request) -> httpx.Response:
244244

245245

246246
@pytest.mark.asyncio
247+
@pytest.mark.parametrize(
248+
"color_model",
249+
[
250+
pytest.param("rgb", id="rgb"),
251+
pytest.param("cmyk", id="cmyk"),
252+
pytest.param("gray", id="gray"),
253+
],
254+
)
247255
async def test_async_convert_to_jpeg_success(
248-
monkeypatch: pytest.MonkeyPatch,
256+
monkeypatch: pytest.MonkeyPatch, color_model: str
249257
) -> None:
250258
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
251259
input_file = make_pdf_file(PdfRestFileID.generate(1))
@@ -257,7 +265,7 @@ async def test_async_convert_to_jpeg_success(
257265
"output_prefix": "async-output",
258266
"page_range": "1-2",
259267
"resolution": 500,
260-
"color_model": "gray",
268+
"color_model": color_model,
261269
"jpeg_quality": 85,
262270
"smoothing": ["all"],
263271
}
@@ -295,7 +303,7 @@ def handler(request: httpx.Request) -> httpx.Response:
295303
output_prefix="async-output",
296304
page_range="1-2",
297305
resolution=500,
298-
color_model="gray",
306+
color_model=color_model,
299307
smoothing=["all"],
300308
jpeg_quality=85,
301309
)

tests/test_convert_to_pdfa.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def handler(request: httpx.Request) -> httpx.Response:
9090
@pytest.mark.parametrize(
9191
"output_type",
9292
[
93-
pytest.param("PDF/A-1b", id="async-pdfa-1b"),
94-
pytest.param("PDF/A-2b", id="async-pdfa-2b"),
95-
pytest.param("PDF/A-2u", id="async-pdfa-2u"),
96-
pytest.param("PDF/A-3b", id="async-pdfa-3b"),
97-
pytest.param("PDF/A-3u", id="async-pdfa-3u"),
93+
pytest.param("PDF/A-1b", id="pdfa-1b"),
94+
pytest.param("PDF/A-2b", id="pdfa-2b"),
95+
pytest.param("PDF/A-2u", id="pdfa-2u"),
96+
pytest.param("PDF/A-3b", id="pdfa-3b"),
97+
pytest.param("PDF/A-3u", id="pdfa-3u"),
9898
],
9999
)
100100
async def test_async_convert_to_pdfa_success(

tests/test_summarize_pdf_text.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,40 @@ def handler(request: httpx.Request) -> httpx.Response:
245245
assert timeout_value == pytest.approx(0.25)
246246

247247

248+
def test_summarize_text_success(monkeypatch: pytest.MonkeyPatch) -> None:
249+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
250+
input_file = make_pdf_file(PdfRestFileID.generate(2))
251+
payload_dump = SummarizePdfTextPayload.model_validate(
252+
{"files": [input_file], "output_type": "json"}
253+
).model_dump(mode="json", by_alias=True, exclude_none=True, exclude_unset=True)
254+
255+
seen: dict[str, int] = {"post": 0}
256+
257+
def handler(request: httpx.Request) -> httpx.Response:
258+
if request.method == "POST" and request.url.path == "/summarized-pdf-text":
259+
seen["post"] += 1
260+
payload = json.loads(request.content.decode("utf-8"))
261+
for key, value in payload_dump.items():
262+
assert payload[key] == value
263+
return httpx.Response(
264+
200,
265+
json={
266+
"summary": "Sync summary",
267+
"inputId": str(input_file.id),
268+
},
269+
)
270+
msg = f"Unexpected request {request.method} {request.url}"
271+
raise AssertionError(msg)
272+
273+
transport = httpx.MockTransport(handler)
274+
with PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client:
275+
response = client.summarize_text(input_file)
276+
277+
assert seen == {"post": 1}
278+
assert isinstance(response, SummarizePdfTextResponse)
279+
assert response.summary == "Sync summary"
280+
281+
248282
@pytest.mark.asyncio
249283
async def test_async_summarize_text_success(
250284
monkeypatch: pytest.MonkeyPatch,

tests/test_translate_pdf_text.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,46 @@ def handler(request: httpx.Request) -> httpx.Response:
237237
assert timeout_value == pytest.approx(0.3)
238238

239239

240+
def test_translate_pdf_text_success(monkeypatch: pytest.MonkeyPatch) -> None:
241+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
242+
input_file = make_pdf_file(PdfRestFileID.generate(2))
243+
payload_dump = TranslatePdfTextPayload.model_validate(
244+
{"files": [input_file], "output_language": "de", "output_type": "json"}
245+
).model_dump(mode="json", by_alias=True, exclude_none=True, exclude_unset=True)
246+
247+
seen: dict[str, int] = {"post": 0}
248+
249+
def handler(request: httpx.Request) -> httpx.Response:
250+
if request.method == "POST" and request.url.path == "/translated-pdf-text":
251+
seen["post"] += 1
252+
payload = json.loads(request.content.decode("utf-8"))
253+
for key, value in payload_dump.items():
254+
assert payload[key] == value
255+
return httpx.Response(
256+
200,
257+
json={
258+
"translated_text": "Hallo",
259+
"inputId": str(input_file.id),
260+
"source_languages": ["en"],
261+
"output_language": "de",
262+
},
263+
)
264+
msg = f"Unexpected request {request.method} {request.url}"
265+
raise AssertionError(msg)
266+
267+
transport = httpx.MockTransport(handler)
268+
with PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client:
269+
response = client.translate_pdf_text(
270+
input_file,
271+
output_language="de",
272+
)
273+
274+
assert seen == {"post": 1}
275+
assert isinstance(response, TranslatePdfTextResponse)
276+
assert response.translated_text == "Hallo"
277+
assert response.source_languages == ["en"]
278+
279+
240280
@pytest.mark.asyncio
241281
async def test_async_translate_pdf_text_success(
242282
monkeypatch: pytest.MonkeyPatch,

0 commit comments

Comments
 (0)