Skip to content

Commit d875637

Browse files
Add missing async live tests
Assisted-by: Codex
1 parent 629047d commit d875637

12 files changed

Lines changed: 501 additions & 12 deletions

tests/live/test_live_convert_to_markdown.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pdfrest import PdfRestApiError, PdfRestClient
5+
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
66
from pdfrest.models import PdfRestFileBasedResponse
77

88
from ..resources import get_test_resource_path
@@ -25,6 +25,25 @@ def test_live_convert_to_markdown_success(
2525
assert response.input_id == uploaded.id
2626

2727

28+
@pytest.mark.asyncio
29+
async def test_live_async_convert_to_markdown_success(
30+
pdfrest_api_key: str,
31+
pdfrest_live_base_url: str,
32+
) -> None:
33+
resource = get_test_resource_path("report.pdf")
34+
async with AsyncPdfRestClient(
35+
api_key=pdfrest_api_key,
36+
base_url=pdfrest_live_base_url,
37+
) as client:
38+
uploaded = (await client.files.create_from_paths([resource]))[0]
39+
response = await client.convert_to_markdown(uploaded, output="async-md")
40+
41+
assert isinstance(response, PdfRestFileBasedResponse)
42+
assert response.output_files
43+
assert response.output_file.name.startswith("async-md")
44+
assert response.input_id == uploaded.id
45+
46+
2847
def test_live_convert_to_markdown_invalid_pages(
2948
pdfrest_api_key: str,
3049
pdfrest_live_base_url: str,
@@ -40,3 +59,21 @@ def test_live_convert_to_markdown_invalid_pages(
4059
uploaded,
4160
extra_body={"pages": "last-1"},
4261
)
62+
63+
64+
@pytest.mark.asyncio
65+
async def test_live_async_convert_to_markdown_invalid_pages(
66+
pdfrest_api_key: str,
67+
pdfrest_live_base_url: str,
68+
) -> None:
69+
resource = get_test_resource_path("report.pdf")
70+
async with AsyncPdfRestClient(
71+
api_key=pdfrest_api_key,
72+
base_url=pdfrest_live_base_url,
73+
) as client:
74+
uploaded = (await client.files.create_from_paths([resource]))[0]
75+
with pytest.raises(PdfRestApiError):
76+
await client.convert_to_markdown(
77+
uploaded,
78+
extra_body={"pages": "last-1"},
79+
)

tests/live/test_live_convert_to_pdfx.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from pdfrest import PdfRestApiError, PdfRestClient
7+
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
88
from pdfrest.models import PdfRestFile
99
from pdfrest.types import PdfXType
1010

@@ -50,6 +50,31 @@ def test_live_convert_to_pdfx_success(
5050
assert output_file.name.startswith("pdfx-live")
5151

5252

53+
@pytest.mark.asyncio
54+
@pytest.mark.parametrize("output_type", PDFX_TYPES, ids=list(PDFX_TYPES))
55+
async def test_live_async_convert_to_pdfx_success(
56+
pdfrest_api_key: str,
57+
pdfrest_live_base_url: str,
58+
uploaded_pdf_for_pdfx: PdfRestFile,
59+
output_type: PdfXType,
60+
) -> None:
61+
async with AsyncPdfRestClient(
62+
api_key=pdfrest_api_key,
63+
base_url=pdfrest_live_base_url,
64+
) as client:
65+
response = await client.convert_to_pdfx(
66+
uploaded_pdf_for_pdfx,
67+
output_type=output_type,
68+
output="async-pdfx",
69+
)
70+
71+
assert response.output_files
72+
output_file = response.output_file
73+
assert output_file.name.startswith("async-pdfx")
74+
assert output_file.type == "application/pdf"
75+
assert str(response.input_id) == str(uploaded_pdf_for_pdfx.id)
76+
77+
5378
@pytest.mark.parametrize(
5479
"invalid_output_type",
5580
[
@@ -76,3 +101,21 @@ def test_live_convert_to_pdfx_invalid_output_type(
76101
output_type="PDF/X-1a",
77102
extra_body={"output_type": invalid_output_type},
78103
)
104+
105+
106+
@pytest.mark.asyncio
107+
async def test_live_async_convert_to_pdfx_invalid_output_type(
108+
pdfrest_api_key: str,
109+
pdfrest_live_base_url: str,
110+
uploaded_pdf_for_pdfx: PdfRestFile,
111+
) -> None:
112+
async with AsyncPdfRestClient(
113+
api_key=pdfrest_api_key,
114+
base_url=pdfrest_live_base_url,
115+
) as client:
116+
with pytest.raises(PdfRestApiError):
117+
await client.convert_to_pdfx(
118+
uploaded_pdf_for_pdfx,
119+
output_type="PDF/X-1a",
120+
extra_body={"output_type": "PDF/X-0"},
121+
)

tests/live/test_live_convert_to_word.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pdfrest import PdfRestApiError, PdfRestClient
5+
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
66
from pdfrest.models import PdfRestFile
77

88
from ..resources import get_test_resource_path
@@ -57,6 +57,31 @@ def test_live_convert_to_word_success(
5757
assert output_file.name.endswith(".docx")
5858

5959

60+
@pytest.mark.asyncio
61+
async def test_live_async_convert_to_word_success(
62+
pdfrest_api_key: str,
63+
pdfrest_live_base_url: str,
64+
uploaded_pdf_for_word: PdfRestFile,
65+
) -> None:
66+
async with AsyncPdfRestClient(
67+
api_key=pdfrest_api_key,
68+
base_url=pdfrest_live_base_url,
69+
) as client:
70+
response = await client.convert_to_word(
71+
uploaded_pdf_for_word,
72+
output="async-word",
73+
)
74+
75+
assert response.output_files
76+
output_file = response.output_file
77+
assert output_file.name.startswith("async-word")
78+
assert (
79+
output_file.type
80+
== "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
81+
)
82+
assert str(response.input_id) == str(uploaded_pdf_for_word.id)
83+
84+
6085
def test_live_convert_to_word_invalid_file_id(
6186
pdfrest_api_key: str,
6287
pdfrest_live_base_url: str,
@@ -73,3 +98,20 @@ def test_live_convert_to_word_invalid_file_id(
7398
uploaded_pdf_for_word,
7499
extra_body={"id": "00000000-0000-0000-0000-000000000000"},
75100
)
101+
102+
103+
@pytest.mark.asyncio
104+
async def test_live_async_convert_to_word_invalid_file_id(
105+
pdfrest_api_key: str,
106+
pdfrest_live_base_url: str,
107+
uploaded_pdf_for_word: PdfRestFile,
108+
) -> None:
109+
async with AsyncPdfRestClient(
110+
api_key=pdfrest_api_key,
111+
base_url=pdfrest_live_base_url,
112+
) as client:
113+
with pytest.raises(PdfRestApiError):
114+
await client.convert_to_word(
115+
uploaded_pdf_for_word,
116+
extra_body={"id": "ffffffff-ffff-ffff-ffff-ffffffffffff"},
117+
)

tests/live/test_live_extract_images.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pdfrest import PdfRestApiError, PdfRestClient
5+
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
66
from pdfrest.models import PdfRestFileBasedResponse
77

88
from ..resources import get_test_resource_path
@@ -25,6 +25,25 @@ def test_live_extract_images_success(
2525
assert response.input_id == uploaded.id
2626

2727

28+
@pytest.mark.asyncio
29+
async def test_live_async_extract_images_success(
30+
pdfrest_api_key: str,
31+
pdfrest_live_base_url: str,
32+
) -> None:
33+
resource = get_test_resource_path("duckhat.pdf")
34+
async with AsyncPdfRestClient(
35+
api_key=pdfrest_api_key,
36+
base_url=pdfrest_live_base_url,
37+
) as client:
38+
uploaded = (await client.files.create_from_paths([resource]))[0]
39+
response = await client.extract_images(uploaded, output="async-images")
40+
41+
assert isinstance(response, PdfRestFileBasedResponse)
42+
assert response.output_files
43+
assert response.output_file.name.startswith("async-images")
44+
assert response.input_id == uploaded.id
45+
46+
2847
def test_live_extract_images_invalid_pages(
2948
pdfrest_api_key: str,
3049
pdfrest_live_base_url: str,
@@ -40,3 +59,21 @@ def test_live_extract_images_invalid_pages(
4059
uploaded,
4160
extra_body={"pages": "last-1"},
4261
)
62+
63+
64+
@pytest.mark.asyncio
65+
async def test_live_async_extract_images_invalid_pages(
66+
pdfrest_api_key: str,
67+
pdfrest_live_base_url: str,
68+
) -> None:
69+
resource = get_test_resource_path("duckhat.pdf")
70+
async with AsyncPdfRestClient(
71+
api_key=pdfrest_api_key,
72+
base_url=pdfrest_live_base_url,
73+
) as client:
74+
uploaded = (await client.files.create_from_paths([resource]))[0]
75+
with pytest.raises(PdfRestApiError):
76+
await client.extract_images(
77+
uploaded,
78+
extra_body={"pages": "last-1"},
79+
)

tests/live/test_live_extract_pdf_text_to_file.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pdfrest import PdfRestApiError, PdfRestClient
5+
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
66
from pdfrest.models import PdfRestFileBasedResponse
77

88
from ..resources import get_test_resource_path
@@ -31,6 +31,32 @@ def test_live_extract_pdf_text_to_file_success(
3131
assert response.input_id == uploaded.id
3232

3333

34+
@pytest.mark.asyncio
35+
async def test_live_async_extract_pdf_text_to_file_success(
36+
pdfrest_api_key: str,
37+
pdfrest_live_base_url: str,
38+
) -> None:
39+
resource = get_test_resource_path("report.pdf")
40+
async with AsyncPdfRestClient(
41+
api_key=pdfrest_api_key,
42+
base_url=pdfrest_live_base_url,
43+
) as client:
44+
uploaded = (await client.files.create_from_paths([resource]))[0]
45+
response = await client.extract_pdf_text_to_file(
46+
uploaded,
47+
full_text="document",
48+
preserve_line_breaks="on",
49+
word_style="off",
50+
word_coordinates="off",
51+
output="async-text",
52+
)
53+
54+
assert isinstance(response, PdfRestFileBasedResponse)
55+
assert response.output_files
56+
assert response.output_file.name.startswith("async-text")
57+
assert response.input_id == uploaded.id
58+
59+
3460
def test_live_extract_pdf_text_to_file_invalid_pages(
3561
pdfrest_api_key: str,
3662
pdfrest_live_base_url: str,
@@ -46,3 +72,21 @@ def test_live_extract_pdf_text_to_file_invalid_pages(
4672
uploaded,
4773
extra_body={"pages": "last-1"},
4874
)
75+
76+
77+
@pytest.mark.asyncio
78+
async def test_live_async_extract_pdf_text_to_file_invalid_pages(
79+
pdfrest_api_key: str,
80+
pdfrest_live_base_url: str,
81+
) -> None:
82+
resource = get_test_resource_path("report.pdf")
83+
async with AsyncPdfRestClient(
84+
api_key=pdfrest_api_key,
85+
base_url=pdfrest_live_base_url,
86+
) as client:
87+
uploaded = (await client.files.create_from_paths([resource]))[0]
88+
with pytest.raises(PdfRestApiError):
89+
await client.extract_pdf_text_to_file(
90+
uploaded,
91+
extra_body={"pages": "last-1"},
92+
)

tests/live/test_live_flatten_pdf_forms.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pdfrest import PdfRestApiError, PdfRestClient
5+
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
66
from pdfrest.models import PdfRestFile
77

88
from ..resources import get_test_resource_path
@@ -54,6 +54,28 @@ def test_live_flatten_pdf_forms(
5454
assert output_file.name.endswith(".pdf")
5555

5656

57+
@pytest.mark.asyncio
58+
async def test_live_async_flatten_pdf_forms_success(
59+
pdfrest_api_key: str,
60+
pdfrest_live_base_url: str,
61+
uploaded_pdf_with_forms: PdfRestFile,
62+
) -> None:
63+
async with AsyncPdfRestClient(
64+
api_key=pdfrest_api_key,
65+
base_url=pdfrest_live_base_url,
66+
) as client:
67+
response = await client.flatten_pdf_forms(
68+
uploaded_pdf_with_forms,
69+
output="async-flattened",
70+
)
71+
72+
assert response.output_files
73+
output_file = response.output_file
74+
assert output_file.name.startswith("async-flattened")
75+
assert output_file.type == "application/pdf"
76+
assert str(response.input_id) == str(uploaded_pdf_with_forms.id)
77+
78+
5779
def test_live_flatten_pdf_forms_invalid_file_id(
5880
pdfrest_api_key: str,
5981
pdfrest_live_base_url: str,
@@ -70,3 +92,20 @@ def test_live_flatten_pdf_forms_invalid_file_id(
7092
uploaded_pdf_with_forms,
7193
extra_body={"id": "ffffffff-ffff-ffff-ffff-ffffffffffff"},
7294
)
95+
96+
97+
@pytest.mark.asyncio
98+
async def test_live_async_flatten_pdf_forms_invalid_file_id(
99+
pdfrest_api_key: str,
100+
pdfrest_live_base_url: str,
101+
uploaded_pdf_with_forms: PdfRestFile,
102+
) -> None:
103+
async with AsyncPdfRestClient(
104+
api_key=pdfrest_api_key,
105+
base_url=pdfrest_live_base_url,
106+
) as client:
107+
with pytest.raises(PdfRestApiError):
108+
await client.flatten_pdf_forms(
109+
uploaded_pdf_with_forms,
110+
extra_body={"id": "00000000-0000-0000-0000-000000000000"},
111+
)

0 commit comments

Comments
 (0)