22
33import pytest
44
5- from pdfrest import PdfRestApiError , PdfRestClient
5+ from pdfrest import AsyncPdfRestClient , PdfRestApiError , PdfRestClient
66from pdfrest .models import PdfRestFile
77
88from ..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+
5779def 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