Skip to content

Commit f6bb554

Browse files
Address remaining smattering of synchronous/async parity in tests
- Excel - JPEG - PDF/A - Convert forms - OCR - Summarize - Translate - PDF/A (live) Assisted-by: Codex
1 parent 559c82b commit f6bb554

8 files changed

Lines changed: 575 additions & 0 deletions

tests/live/test_live_convert_to_pdfa.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ def test_live_convert_to_pdfa_with_rasterize_option(
101101
assert str(response.input_id) == str(uploaded_pdf_for_pdfa.id)
102102

103103

104+
@pytest.mark.asyncio
105+
async def test_live_async_convert_to_pdfa_with_rasterize_option(
106+
pdfrest_api_key: str,
107+
pdfrest_live_base_url: str,
108+
uploaded_pdf_for_pdfa: PdfRestFile,
109+
) -> None:
110+
async with AsyncPdfRestClient(
111+
api_key=pdfrest_api_key,
112+
base_url=pdfrest_live_base_url,
113+
) as client:
114+
response = await client.convert_to_pdfa(
115+
uploaded_pdf_for_pdfa,
116+
output_type="PDF/A-2b",
117+
rasterize_if_errors_encountered="on",
118+
output="async-pdfa-rasterize",
119+
)
120+
121+
assert response.output_files
122+
output_file = response.output_file
123+
assert output_file.name.startswith("async-pdfa-rasterize")
124+
assert output_file.type == "application/pdf"
125+
assert str(response.input_id) == str(uploaded_pdf_for_pdfa.id)
126+
127+
104128
@pytest.mark.parametrize(
105129
"invalid_output_type",
106130
[

tests/test_convert_to_excel.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,31 @@ def test_convert_to_excel_validation(monkeypatch: pytest.MonkeyPatch) -> None:
273273
),
274274
):
275275
client.convert_to_excel([pdf_file, make_pdf_file(PdfRestFileID.generate())])
276+
277+
278+
@pytest.mark.asyncio
279+
async def test_async_convert_to_excel_validation(
280+
monkeypatch: pytest.MonkeyPatch,
281+
) -> None:
282+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
283+
pdf_file = make_pdf_file(PdfRestFileID.generate(1))
284+
png_file = PdfRestFile.model_validate(
285+
build_file_info_payload(
286+
PdfRestFileID.generate(),
287+
"example.png",
288+
"image/png",
289+
)
290+
)
291+
transport = httpx.MockTransport(lambda request: (_ for _ in ()).throw(RuntimeError))
292+
293+
async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client:
294+
with pytest.raises(ValidationError, match="Must be a PDF file"):
295+
await client.convert_to_excel(png_file)
296+
297+
async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client:
298+
with pytest.raises(
299+
ValidationError, match="List should have at most 1 item after validation"
300+
):
301+
await client.convert_to_excel(
302+
[pdf_file, make_pdf_file(PdfRestFileID.generate())]
303+
)

0 commit comments

Comments
 (0)