@@ -150,6 +150,91 @@ def handler(request: httpx.Request) -> httpx.Response:
150150 assert response .output_file .type == "application/pdf"
151151
152152
153+ def test_blank_pdf_defaults (monkeypatch : pytest .MonkeyPatch ) -> None :
154+ monkeypatch .delenv ("PDFREST_API_KEY" , raising = False )
155+ output_id = str (PdfRestFileID .generate ())
156+
157+ payload_dump = PdfBlankPayload .model_validate (
158+ {
159+ "page_size" : "letter" ,
160+ "page_count" : 1 ,
161+ "page_orientation" : "portrait" ,
162+ }
163+ ).model_dump (mode = "json" , by_alias = True , exclude_none = True , exclude_unset = True )
164+
165+ seen : dict [str , int ] = {"post" : 0 , "get" : 0 }
166+
167+ def handler (request : httpx .Request ) -> httpx .Response :
168+ if request .method == "POST" and request .url .path == "/blank-pdf" :
169+ seen ["post" ] += 1
170+ payload = json .loads (request .content .decode ("utf-8" ))
171+ assert payload == payload_dump
172+ return httpx .Response (200 , json = {"outputId" : [output_id ]})
173+ if request .method == "GET" and request .url .path == f"/resource/{ output_id } " :
174+ seen ["get" ] += 1
175+ return httpx .Response (
176+ 200 ,
177+ json = build_file_info_payload (
178+ output_id ,
179+ "blank-default.pdf" ,
180+ "application/pdf" ,
181+ ),
182+ )
183+ msg = f"Unexpected request { request .method } { request .url } "
184+ raise AssertionError (msg )
185+
186+ transport = httpx .MockTransport (handler )
187+ with PdfRestClient (api_key = VALID_API_KEY , transport = transport ) as client :
188+ response = client .blank_pdf ()
189+
190+ assert seen == {"post" : 1 , "get" : 1 }
191+ assert isinstance (response , PdfRestFileBasedResponse )
192+ assert response .output_file .type == "application/pdf"
193+
194+
195+ @pytest .mark .asyncio
196+ async def test_async_blank_pdf_defaults (monkeypatch : pytest .MonkeyPatch ) -> None :
197+ monkeypatch .delenv ("PDFREST_API_KEY" , raising = False )
198+ output_id = str (PdfRestFileID .generate ())
199+
200+ payload_dump = PdfBlankPayload .model_validate (
201+ {
202+ "page_size" : "letter" ,
203+ "page_count" : 1 ,
204+ "page_orientation" : "portrait" ,
205+ }
206+ ).model_dump (mode = "json" , by_alias = True , exclude_none = True , exclude_unset = True )
207+
208+ seen : dict [str , int ] = {"post" : 0 , "get" : 0 }
209+
210+ def handler (request : httpx .Request ) -> httpx .Response :
211+ if request .method == "POST" and request .url .path == "/blank-pdf" :
212+ seen ["post" ] += 1
213+ payload = json .loads (request .content .decode ("utf-8" ))
214+ assert payload == payload_dump
215+ return httpx .Response (200 , json = {"outputId" : [output_id ]})
216+ if request .method == "GET" and request .url .path == f"/resource/{ output_id } " :
217+ seen ["get" ] += 1
218+ return httpx .Response (
219+ 200 ,
220+ json = build_file_info_payload (
221+ output_id ,
222+ "blank-async-default.pdf" ,
223+ "application/pdf" ,
224+ ),
225+ )
226+ msg = f"Unexpected request { request .method } { request .url } "
227+ raise AssertionError (msg )
228+
229+ transport = httpx .MockTransport (handler )
230+ async with AsyncPdfRestClient (api_key = ASYNC_API_KEY , transport = transport ) as client :
231+ response = await client .blank_pdf ()
232+
233+ assert seen == {"post" : 1 , "get" : 1 }
234+ assert isinstance (response , PdfRestFileBasedResponse )
235+ assert response .output_file .type == "application/pdf"
236+
237+
153238@pytest .mark .parametrize (
154239 "page_count" ,
155240 [
@@ -597,12 +682,6 @@ def test_blank_pdf_validation(monkeypatch: pytest.MonkeyPatch) -> None:
597682 monkeypatch .delenv ("PDFREST_API_KEY" , raising = False )
598683 transport = httpx .MockTransport (lambda request : (_ for _ in ()).throw (RuntimeError ))
599684
600- with (
601- PdfRestClient (api_key = VALID_API_KEY , transport = transport ) as client ,
602- pytest .raises (ValueError , match = "page_orientation is required" ),
603- ):
604- client .blank_pdf (page_size = "letter" , page_count = 1 )
605-
606685 with (
607686 PdfRestClient (api_key = VALID_API_KEY , transport = transport ) as client ,
608687 pytest .raises (ValueError , match = "Custom page sizes must contain exactly two" ),
0 commit comments