11from __future__ import annotations
22
33import json
4+ from typing import cast
45
56import httpx
67import pytest
910from pdfrest import AsyncPdfRestClient , PdfRestClient
1011from pdfrest .models import PdfRestFileBasedResponse , PdfRestFileID
1112from pdfrest .models ._internal import PdfBlankPayload
13+ from pdfrest .types import PdfCustomPageSize
1214
1315from .graphics_test_helpers import ASYNC_API_KEY , VALID_API_KEY , build_file_info_payload
1416
@@ -384,15 +386,31 @@ async def test_async_blank_pdf_page_count_boundaries_validation(
384386@pytest .mark .parametrize (
385387 ("page_size" , "match" ),
386388 [
387- pytest .param ((0.0 , 10.0 ), "greater than 0" , id = "height-zero" ),
388- pytest .param ((- 1.0 , 10.0 ), "greater than 0" , id = "height-negative" ),
389- pytest .param ((10.0 , 0.0 ), "greater than 0" , id = "width-zero" ),
390- pytest .param ((10.0 , - 1.0 ), "greater than 0" , id = "width-negative" ),
389+ pytest .param (
390+ {"custom_height" : 0.0 , "custom_width" : 10.0 },
391+ "greater than 0" ,
392+ id = "height-zero" ,
393+ ),
394+ pytest .param (
395+ {"custom_height" : - 1.0 , "custom_width" : 10.0 },
396+ "greater than 0" ,
397+ id = "height-negative" ,
398+ ),
399+ pytest .param (
400+ {"custom_height" : 10.0 , "custom_width" : 0.0 },
401+ "greater than 0" ,
402+ id = "width-zero" ,
403+ ),
404+ pytest .param (
405+ {"custom_height" : 10.0 , "custom_width" : - 1.0 },
406+ "greater than 0" ,
407+ id = "width-negative" ,
408+ ),
391409 ],
392410)
393411def test_blank_pdf_custom_dimensions_validation (
394412 monkeypatch : pytest .MonkeyPatch ,
395- page_size : tuple [ float , float ] ,
413+ page_size : PdfCustomPageSize ,
396414 match : str ,
397415) -> None :
398416 monkeypatch .delenv ("PDFREST_API_KEY" , raising = False )
@@ -412,15 +430,31 @@ def test_blank_pdf_custom_dimensions_validation(
412430@pytest .mark .parametrize (
413431 ("page_size" , "match" ),
414432 [
415- pytest .param ((0.0 , 10.0 ), "greater than 0" , id = "height-zero" ),
416- pytest .param ((- 1.0 , 10.0 ), "greater than 0" , id = "height-negative" ),
417- pytest .param ((10.0 , 0.0 ), "greater than 0" , id = "width-zero" ),
418- pytest .param ((10.0 , - 1.0 ), "greater than 0" , id = "width-negative" ),
433+ pytest .param (
434+ {"custom_height" : 0.0 , "custom_width" : 10.0 },
435+ "greater than 0" ,
436+ id = "height-zero" ,
437+ ),
438+ pytest .param (
439+ {"custom_height" : - 1.0 , "custom_width" : 10.0 },
440+ "greater than 0" ,
441+ id = "height-negative" ,
442+ ),
443+ pytest .param (
444+ {"custom_height" : 10.0 , "custom_width" : 0.0 },
445+ "greater than 0" ,
446+ id = "width-zero" ,
447+ ),
448+ pytest .param (
449+ {"custom_height" : 10.0 , "custom_width" : - 1.0 },
450+ "greater than 0" ,
451+ id = "width-negative" ,
452+ ),
419453 ],
420454)
421455async def test_async_blank_pdf_custom_dimensions_validation (
422456 monkeypatch : pytest .MonkeyPatch ,
423- page_size : tuple [ float , float ] ,
457+ page_size : PdfCustomPageSize ,
424458 match : str ,
425459) -> None :
426460 monkeypatch .delenv ("PDFREST_API_KEY" , raising = False )
@@ -537,7 +571,7 @@ def handler(request: httpx.Request) -> httpx.Response:
537571 transport = httpx .MockTransport (handler )
538572 with PdfRestClient (api_key = VALID_API_KEY , transport = transport ) as client :
539573 response = client .blank_pdf (
540- page_size = ( 792 , 612 ) ,
574+ page_size = { "custom_height" : 792 , "custom_width" : 612 } ,
541575 page_count = 3 ,
542576 output = "custom" ,
543577 extra_query = {"trace" : "true" },
@@ -658,7 +692,7 @@ def handler(request: httpx.Request) -> httpx.Response:
658692 transport = httpx .MockTransport (handler )
659693 async with AsyncPdfRestClient (api_key = ASYNC_API_KEY , transport = transport ) as client :
660694 response = await client .blank_pdf (
661- page_size = ( 100 , 50 ) ,
695+ page_size = { "custom_height" : 100 , "custom_width" : 50 } ,
662696 page_count = 1 ,
663697 extra_query = {"trace" : "async" },
664698 extra_headers = {"X-Debug" : "async" },
@@ -684,16 +718,24 @@ def test_blank_pdf_validation(monkeypatch: pytest.MonkeyPatch) -> None:
684718
685719 with (
686720 PdfRestClient (api_key = VALID_API_KEY , transport = transport ) as client ,
687- pytest .raises (ValueError , match = "Custom page sizes must contain exactly two" ),
721+ pytest .raises (
722+ ValueError , match = "must include both custom_height and custom_width"
723+ ),
688724 ):
689- client .blank_pdf (page_size = (50 ,), page_count = 1 )
725+ client .blank_pdf (
726+ page_size = cast (
727+ PdfCustomPageSize ,
728+ cast (object , {"custom_height" : 50 }),
729+ ),
730+ page_count = 1 ,
731+ )
690732
691733 with (
692734 PdfRestClient (api_key = VALID_API_KEY , transport = transport ) as client ,
693735 pytest .raises (ValueError , match = "page_orientation must be omitted" ),
694736 ):
695737 client .blank_pdf (
696- page_size = ( 10 , 10 ) ,
738+ page_size = { "custom_height" : 10 , "custom_width" : 10 } ,
697739 page_count = 1 ,
698740 page_orientation = "portrait" ,
699741 )
0 commit comments