Skip to content

Commit c3a1c1f

Browse files
Fill in missing live tests of conversion methods
Assisted-by: Codex
1 parent 432ccfa commit c3a1c1f

7 files changed

Lines changed: 119 additions & 12 deletions

tests/live/test_live_convert_to_excel.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,35 @@ def test_live_convert_to_excel_success(
6060

6161

6262
@pytest.mark.asyncio
63+
@pytest.mark.parametrize(
64+
"output_name",
65+
[
66+
pytest.param(None, id="default-output"),
67+
pytest.param("async-excel", id="custom-output"),
68+
],
69+
)
6370
async def test_live_async_convert_to_excel_success(
6471
pdfrest_api_key: str,
6572
pdfrest_live_base_url: str,
6673
uploaded_pdf_for_excel: PdfRestFile,
74+
output_name: str | None,
6775
) -> None:
76+
kwargs: dict[str, str] = {}
77+
if output_name is not None:
78+
kwargs["output"] = output_name
79+
6880
async with AsyncPdfRestClient(
6981
api_key=pdfrest_api_key,
7082
base_url=pdfrest_live_base_url,
7183
) as client:
72-
response = await client.convert_to_excel(uploaded_pdf_for_excel, output="async")
84+
response = await client.convert_to_excel(uploaded_pdf_for_excel, **kwargs)
7385

7486
assert response.output_files
7587
output_file = response.output_file
76-
assert output_file.name.startswith("async")
88+
if output_name is not None:
89+
assert output_file.name.startswith(output_name)
90+
else:
91+
assert output_file.name.endswith(".xlsx")
7792
assert (
7893
output_file.type
7994
== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

tests/live/test_live_convert_to_pdfa.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,19 @@ def test_live_convert_to_pdfa_invalid_output_type(
130130

131131

132132
@pytest.mark.asyncio
133+
@pytest.mark.parametrize(
134+
"invalid_output_type",
135+
[
136+
pytest.param("PDF/A-0", id="pdfa-0"),
137+
pytest.param("PDF/A-99", id="pdfa-99"),
138+
pytest.param("pdf/a-2b", id="lowercase"),
139+
],
140+
)
133141
async def test_live_async_convert_to_pdfa_invalid_output_type(
134142
pdfrest_api_key: str,
135143
pdfrest_live_base_url: str,
136144
uploaded_pdf_for_pdfa: PdfRestFile,
145+
invalid_output_type: str,
137146
) -> None:
138147
async with AsyncPdfRestClient(
139148
api_key=pdfrest_api_key,
@@ -143,5 +152,5 @@ async def test_live_async_convert_to_pdfa_invalid_output_type(
143152
await client.convert_to_pdfa(
144153
uploaded_pdf_for_pdfa,
145154
output_type="PDF/A-1b",
146-
extra_body={"output_type": "PDF/A-0"},
155+
extra_body={"output_type": invalid_output_type},
147156
)

tests/live/test_live_convert_to_pdfx.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,19 @@ def test_live_convert_to_pdfx_invalid_output_type(
104104

105105

106106
@pytest.mark.asyncio
107+
@pytest.mark.parametrize(
108+
"invalid_output_type",
109+
[
110+
pytest.param("PDF/X-0", id="pdfx-0"),
111+
pytest.param("PDF/X-99", id="pdfx-99"),
112+
pytest.param("pdf/x-4", id="lowercase"),
113+
],
114+
)
107115
async def test_live_async_convert_to_pdfx_invalid_output_type(
108116
pdfrest_api_key: str,
109117
pdfrest_live_base_url: str,
110118
uploaded_pdf_for_pdfx: PdfRestFile,
119+
invalid_output_type: str,
111120
) -> None:
112121
async with AsyncPdfRestClient(
113122
api_key=pdfrest_api_key,
@@ -117,5 +126,5 @@ async def test_live_async_convert_to_pdfx_invalid_output_type(
117126
await client.convert_to_pdfx(
118127
uploaded_pdf_for_pdfx,
119128
output_type="PDF/X-1a",
120-
extra_body={"output_type": "PDF/X-0"},
129+
extra_body={"output_type": invalid_output_type},
121130
)

tests/live/test_live_convert_to_powerpoint.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,37 @@ def test_live_convert_to_powerpoint_success(
6060

6161

6262
@pytest.mark.asyncio
63+
@pytest.mark.parametrize(
64+
"output_name",
65+
[
66+
pytest.param(None, id="default-output"),
67+
pytest.param("async-powerpoint", id="custom-output"),
68+
],
69+
)
6370
async def test_live_async_convert_to_powerpoint_success(
6471
pdfrest_api_key: str,
6572
pdfrest_live_base_url: str,
6673
uploaded_pdf_for_powerpoint: PdfRestFile,
74+
output_name: str | None,
6775
) -> None:
76+
kwargs: dict[str, str] = {}
77+
if output_name is not None:
78+
kwargs["output"] = output_name
79+
6880
async with AsyncPdfRestClient(
6981
api_key=pdfrest_api_key,
7082
base_url=pdfrest_live_base_url,
7183
) as client:
7284
response = await client.convert_to_powerpoint(
73-
uploaded_pdf_for_powerpoint, output="async"
85+
uploaded_pdf_for_powerpoint, **kwargs
7486
)
7587

7688
assert response.output_files
7789
output_file = response.output_file
78-
assert output_file.name.startswith("async")
90+
if output_name is not None:
91+
assert output_file.name.startswith(output_name)
92+
else:
93+
assert output_file.name.endswith(".pptx")
7994
assert (
8095
output_file.type
8196
== "application/vnd.openxmlformats-officedocument.presentationml.presentation"

tests/live/test_live_convert_to_word.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,38 @@ def test_live_convert_to_word_success(
5858

5959

6060
@pytest.mark.asyncio
61+
@pytest.mark.parametrize(
62+
"output_name",
63+
[
64+
pytest.param(None, id="default-output"),
65+
pytest.param("async-word", id="custom-output"),
66+
],
67+
)
6168
async def test_live_async_convert_to_word_success(
6269
pdfrest_api_key: str,
6370
pdfrest_live_base_url: str,
6471
uploaded_pdf_for_word: PdfRestFile,
72+
output_name: str | None,
6573
) -> None:
74+
kwargs: dict[str, str] = {}
75+
if output_name is not None:
76+
kwargs["output"] = output_name
77+
6678
async with AsyncPdfRestClient(
6779
api_key=pdfrest_api_key,
6880
base_url=pdfrest_live_base_url,
6981
) as client:
7082
response = await client.convert_to_word(
7183
uploaded_pdf_for_word,
72-
output="async-word",
84+
**kwargs,
7385
)
7486

7587
assert response.output_files
7688
output_file = response.output_file
77-
assert output_file.name.startswith("async-word")
89+
if output_name is not None:
90+
assert output_file.name.startswith(output_name)
91+
else:
92+
assert output_file.name.endswith(".docx")
7893
assert (
7994
output_file.type
8095
== "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

tests/live/test_live_convert_xfa_to_acroforms.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,29 @@ def test_live_convert_xfa_to_acroforms_invalid_file_id(
8383

8484

8585
@pytest.mark.asyncio
86+
@pytest.mark.parametrize(
87+
"output_name",
88+
[
89+
pytest.param(None, id="default-output"),
90+
pytest.param("async-acroforms", id="custom-output"),
91+
],
92+
)
8693
async def test_live_async_convert_xfa_to_acroforms_success(
8794
pdfrest_api_key: str,
8895
pdfrest_live_base_url: str,
8996
uploaded_pdf_for_acroforms: PdfRestFile,
97+
output_name: str | None,
9098
) -> None:
99+
kwargs: dict[str, str] = {}
100+
if output_name is not None:
101+
kwargs["output"] = output_name
102+
91103
async with AsyncPdfRestClient(
92104
api_key=pdfrest_api_key,
93105
base_url=pdfrest_live_base_url,
94106
) as client:
95107
response = await client.convert_xfa_to_acroforms(
96-
uploaded_pdf_for_acroforms, output="async"
108+
uploaded_pdf_for_acroforms, **kwargs
97109
)
98110

99111
assert str(response.input_id) == str(uploaded_pdf_for_acroforms.id)
@@ -104,7 +116,10 @@ async def test_live_async_convert_xfa_to_acroforms_success(
104116

105117
assert response.output_files
106118
output_file = response.output_file
107-
assert output_file.name.startswith("async")
119+
if output_name is not None:
120+
assert output_file.name.startswith(output_name)
121+
else:
122+
assert output_file.name.endswith(".pdf")
108123
assert output_file.type == "application/pdf"
109124
assert output_file.size > 0
110125

tests/live/test_live_graphic_conversions.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ def uploaded_20_page_pdf(
121121
return client.files.create_from_paths([resource])[0]
122122

123123

124+
def test_live_convert_to_png_success(
125+
pdfrest_api_key: str,
126+
pdfrest_live_base_url: str,
127+
) -> None:
128+
resource = get_test_resource_path("report.pdf")
129+
with PdfRestClient(
130+
api_key=pdfrest_api_key,
131+
base_url=pdfrest_live_base_url,
132+
) as client:
133+
uploaded = client.files.create_from_paths([resource])[0]
134+
response = client.convert_to_png(
135+
uploaded,
136+
output_prefix="live-png",
137+
resolution=150,
138+
)
139+
140+
assert response.output_files
141+
assert all(file_info.type == "image/png" for file_info in response.output_files)
142+
assert str(response.input_id) == str(uploaded.id)
143+
144+
124145
@pytest.mark.asyncio
125146
async def test_live_async_convert_to_png_success(
126147
pdfrest_api_key: str,
@@ -292,21 +313,29 @@ def test_live_graphic_invalid_smoothing(
292313

293314

294315
@pytest.mark.asyncio
316+
@pytest.mark.parametrize(
317+
("_endpoint_label", "spec", "invalid_smoothing"),
318+
_invalid_smoothing_cases(),
319+
)
295320
async def test_live_async_graphic_invalid_smoothing(
296321
pdfrest_api_key: str,
297322
pdfrest_live_base_url: str,
323+
_endpoint_label: str,
324+
spec: _GraphicEndpointSpec,
325+
invalid_smoothing: Any,
298326
) -> None:
299327
resource = get_test_resource_path("report.pdf")
300328
async with AsyncPdfRestClient(
301329
api_key=pdfrest_api_key,
302330
base_url=pdfrest_live_base_url,
303331
) as client:
304332
uploaded = (await client.files.create_from_paths([resource]))[0]
333+
client_method = getattr(client, spec.method_name)
305334
with pytest.raises(PdfRestApiError, match=r"(?i)smooth"):
306-
await client.convert_to_png(
335+
await client_method(
307336
uploaded,
308337
smoothing="none",
309-
extra_body={"smoothing": "super-smooth"},
338+
extra_body={"smoothing": invalid_smoothing},
310339
)
311340

312341

0 commit comments

Comments
 (0)