44
55from pdfrest import AsyncPdfRestClient , PdfRestApiError , PdfRestClient
66
7+ BLANK_PDF_LITERAL_CASES = [
8+ pytest .param (
9+ "letter" ,
10+ "portrait" ,
11+ None ,
12+ None ,
13+ "blank-letter" ,
14+ id = "letter-portrait" ,
15+ ),
16+ pytest .param (
17+ "legal" ,
18+ "landscape" ,
19+ None ,
20+ None ,
21+ "blank-legal" ,
22+ id = "legal-landscape" ,
23+ ),
24+ pytest .param (
25+ "ledger" ,
26+ "portrait" ,
27+ None ,
28+ None ,
29+ "blank-ledger" ,
30+ id = "ledger-portrait" ,
31+ ),
32+ pytest .param (
33+ "A3" ,
34+ "landscape" ,
35+ None ,
36+ None ,
37+ "blank-a3" ,
38+ id = "a3-landscape" ,
39+ ),
40+ pytest .param (
41+ "A4" ,
42+ "portrait" ,
43+ None ,
44+ None ,
45+ "blank-a4" ,
46+ id = "a4-portrait" ,
47+ ),
48+ pytest .param (
49+ "A5" ,
50+ "landscape" ,
51+ None ,
52+ None ,
53+ "blank-a5" ,
54+ id = "a5-landscape" ,
55+ ),
56+ pytest .param (
57+ "custom" ,
58+ None ,
59+ 792.0 ,
60+ 612.0 ,
61+ "blank-custom" ,
62+ id = "custom-dimensions" ,
63+ ),
64+ ]
65+
766
867@pytest .mark .parametrize (
9- "output_name" ,
10- [
11- pytest .param (None , id = "default-output" ),
12- pytest .param ("blank-doc" , id = "custom-output" ),
13- ],
68+ ("page_size" , "page_orientation" , "custom_height" , "custom_width" , "output_name" ),
69+ BLANK_PDF_LITERAL_CASES ,
1470)
1571def test_live_blank_pdf_success (
1672 pdfrest_api_key : str ,
1773 pdfrest_live_base_url : str ,
18- output_name : str | None ,
74+ page_size : str ,
75+ page_orientation : str | None ,
76+ custom_height : float | None ,
77+ custom_width : float | None ,
78+ output_name : str ,
1979) -> None :
20- kwargs : dict [str , str | int ] = {
21- "page_size" : "letter" ,
80+ kwargs : dict [str , str | int | float ] = {
81+ "page_size" : page_size ,
2282 "page_count" : 1 ,
23- "page_orientation " : "portrait" ,
83+ "output " : output_name ,
2484 }
25- if output_name is not None :
26- kwargs ["output" ] = output_name
85+ if page_orientation is not None :
86+ kwargs ["page_orientation" ] = page_orientation
87+ if custom_height is not None :
88+ kwargs ["custom_height" ] = custom_height
89+ if custom_width is not None :
90+ kwargs ["custom_width" ] = custom_width
2791
2892 with PdfRestClient (
2993 api_key = pdfrest_api_key ,
@@ -36,31 +100,44 @@ def test_live_blank_pdf_success(
36100 assert output_file .type == "application/pdf"
37101 assert output_file .size > 0
38102 assert response .warning is None
39- if output_name is not None :
40- assert output_file .name .startswith (output_name )
41- else :
42- assert output_file .name .endswith (".pdf" )
103+ assert output_file .name .startswith (output_name )
43104
44105
45106@pytest .mark .asyncio
107+ @pytest .mark .parametrize (
108+ ("page_size" , "page_orientation" , "custom_height" , "custom_width" , "output_name" ),
109+ BLANK_PDF_LITERAL_CASES ,
110+ )
46111async def test_live_async_blank_pdf_success (
47112 pdfrest_api_key : str ,
48113 pdfrest_live_base_url : str ,
114+ page_size : str ,
115+ page_orientation : str | None ,
116+ custom_height : float | None ,
117+ custom_width : float | None ,
118+ output_name : str ,
49119) -> None :
120+ kwargs : dict [str , str | int | float ] = {
121+ "page_size" : page_size ,
122+ "page_count" : 2 ,
123+ "output" : output_name ,
124+ }
125+ if page_orientation is not None :
126+ kwargs ["page_orientation" ] = page_orientation
127+ if custom_height is not None :
128+ kwargs ["custom_height" ] = custom_height
129+ if custom_width is not None :
130+ kwargs ["custom_width" ] = custom_width
131+
50132 async with AsyncPdfRestClient (
51133 api_key = pdfrest_api_key ,
52134 base_url = pdfrest_live_base_url ,
53135 ) as client :
54- response = await client .blank_pdf (
55- page_size = "A4" ,
56- page_count = 2 ,
57- page_orientation = "landscape" ,
58- output = "async-blank" ,
59- )
136+ response = await client .blank_pdf (** kwargs )
60137
61138 assert response .output_files
62139 output_file = response .output_file
63- assert output_file .name .startswith ("async-blank" )
140+ assert output_file .name .startswith (output_name )
64141 assert output_file .type == "application/pdf"
65142 assert output_file .size > 0
66143 assert response .warning is None
0 commit comments