@@ -191,6 +191,35 @@ def test_live_graphic_valid_color_models(
191191 assert response .output_files
192192
193193
194+ @pytest .mark .asyncio
195+ @pytest .mark .parametrize (
196+ ("_endpoint_label" , "spec" , "color_model" ),
197+ _valid_color_cases (),
198+ )
199+ async def test_live_async_graphic_valid_color_models (
200+ pdfrest_api_key : str ,
201+ pdfrest_live_base_url : str ,
202+ _endpoint_label : str ,
203+ spec : _GraphicEndpointSpec ,
204+ color_model : str ,
205+ ) -> None :
206+ resource = get_test_resource_path ("report.pdf" )
207+ payload_model = spec .payload_model
208+ resolution = _resolution_bounds (payload_model )[0 ]
209+ async with AsyncPdfRestClient (
210+ api_key = pdfrest_api_key ,
211+ base_url = pdfrest_live_base_url ,
212+ ) as client :
213+ uploaded = (await client .files .create_from_paths ([resource ]))[0 ]
214+ client_method = getattr (client , spec .method_name )
215+ response = await client_method (
216+ uploaded ,
217+ color_model = color_model ,
218+ resolution = resolution ,
219+ )
220+ assert response .output_files
221+
222+
194223@pytest .mark .parametrize (
195224 ("_endpoint_label" , "spec" , "invalid_color" ),
196225 _invalid_color_cases (),
@@ -219,6 +248,35 @@ def test_live_graphic_invalid_color_model(
219248 )
220249
221250
251+ @pytest .mark .asyncio
252+ @pytest .mark .parametrize (
253+ ("_endpoint_label" , "spec" , "invalid_color" ),
254+ _invalid_color_cases (),
255+ )
256+ async def test_live_async_graphic_invalid_color_model (
257+ pdfrest_api_key : str ,
258+ pdfrest_live_base_url : str ,
259+ _endpoint_label : str ,
260+ spec : _GraphicEndpointSpec ,
261+ invalid_color : str ,
262+ ) -> None :
263+ payload_model = spec .payload_model
264+
265+ resource = get_test_resource_path ("report.pdf" )
266+ async with AsyncPdfRestClient (
267+ api_key = pdfrest_api_key , base_url = pdfrest_live_base_url
268+ ) as client :
269+ uploaded = (await client .files .create_from_paths ([resource ]))[0 ]
270+ client_method = getattr (client , spec .method_name )
271+ resolution = _resolution_bounds (payload_model )[0 ]
272+ with pytest .raises (PdfRestApiError , match = r"(?i)color" ):
273+ await client_method (
274+ uploaded ,
275+ resolution = resolution ,
276+ extra_body = {"color_model" : invalid_color },
277+ )
278+
279+
222280@pytest .mark .parametrize (
223281 ("_endpoint_label" , "spec" ),
224282 PNG_PAYLOAD_ONLY .items (),
@@ -263,6 +321,51 @@ def test_live_graphic_resolution_bounds(
263321 assert response .output_files
264322
265323
324+ @pytest .mark .asyncio
325+ @pytest .mark .parametrize (
326+ ("_endpoint_label" , "spec" ),
327+ PNG_PAYLOAD_ONLY .items (),
328+ ids = list (PNG_PAYLOAD_ONLY ),
329+ )
330+ @pytest .mark .parametrize (
331+ ("bound" , "offset" , "should_raise" ),
332+ [
333+ pytest .param ("min" , 0 , False , id = "min" ),
334+ pytest .param ("max" , 0 , False , id = "max" ),
335+ pytest .param ("min" , - 1 , True , id = "below-min" ),
336+ pytest .param ("max" , 1 , True , id = "above-max" ),
337+ ],
338+ )
339+ async def test_live_async_graphic_resolution_bounds (
340+ pdfrest_api_key : str ,
341+ pdfrest_live_base_url : str ,
342+ _endpoint_label : str ,
343+ spec : _GraphicEndpointSpec ,
344+ bound : str ,
345+ offset : int ,
346+ should_raise : bool ,
347+ ) -> None :
348+ payload_model = spec .payload_model
349+ min_res , max_res = _resolution_bounds (payload_model )
350+ resource = get_test_resource_path ("report.pdf" )
351+
352+ async with AsyncPdfRestClient (
353+ api_key = pdfrest_api_key , base_url = pdfrest_live_base_url
354+ ) as client :
355+ uploaded = (await client .files .create_from_paths ([resource ]))[0 ]
356+ client_method = getattr (client , spec .method_name )
357+ base_resolution = min_res if bound == "min" else max_res
358+ call_kwargs : dict [str , Any ] = {"resolution" : base_resolution }
359+
360+ if should_raise :
361+ call_kwargs ["extra_body" ] = {"resolution" : base_resolution + offset }
362+ with pytest .raises (PdfRestApiError , match = r"(?i)resolution" ):
363+ await client_method (uploaded , ** call_kwargs )
364+ else :
365+ response = await client_method (uploaded , ** call_kwargs )
366+ assert response .output_files
367+
368+
266369@pytest .mark .parametrize (
267370 ("_endpoint_label" , "spec" , "smoothing_value" ),
268371 _valid_smoothing_cases (),
@@ -287,6 +390,31 @@ def test_live_graphic_valid_smoothing(
287390 assert response .output_files
288391
289392
393+ @pytest .mark .asyncio
394+ @pytest .mark .parametrize (
395+ ("_endpoint_label" , "spec" , "smoothing_value" ),
396+ _valid_smoothing_cases (),
397+ )
398+ async def test_live_async_graphic_valid_smoothing (
399+ pdfrest_api_key : str ,
400+ pdfrest_live_base_url : str ,
401+ _endpoint_label : str ,
402+ spec : _GraphicEndpointSpec ,
403+ smoothing_value : str ,
404+ ) -> None :
405+ resource = get_test_resource_path ("report.pdf" )
406+ async with AsyncPdfRestClient (
407+ api_key = pdfrest_api_key , base_url = pdfrest_live_base_url
408+ ) as client :
409+ uploaded = (await client .files .create_from_paths ([resource ]))[0 ]
410+ client_method = getattr (client , spec .method_name )
411+ response = await client_method (
412+ uploaded ,
413+ smoothing = smoothing_value ,
414+ )
415+ assert response .output_files
416+
417+
290418@pytest .mark .parametrize (
291419 ("_endpoint_label" , "spec" , "invalid_smoothing" ),
292420 _invalid_smoothing_cases (),
@@ -326,8 +454,7 @@ async def test_live_async_graphic_invalid_smoothing(
326454) -> None :
327455 resource = get_test_resource_path ("report.pdf" )
328456 async with AsyncPdfRestClient (
329- api_key = pdfrest_api_key ,
330- base_url = pdfrest_live_base_url ,
457+ api_key = pdfrest_api_key , base_url = pdfrest_live_base_url
331458 ) as client :
332459 uploaded = (await client .files .create_from_paths ([resource ]))[0 ]
333460 client_method = getattr (client , spec .method_name )
@@ -394,6 +521,62 @@ def test_live_png_page_range_variants(
394521 )
395522
396523
524+ @pytest .mark .asyncio
525+ @pytest .mark .parametrize (
526+ ("page_range" , "expect_success" ),
527+ [
528+ pytest .param ("5" , True , id = "single" ),
529+ pytest .param ("3-7" , True , id = "ascending-range" ),
530+ pytest .param ("last" , True , id = "last" ),
531+ pytest .param ("1-last" , True , id = "entire-document" ),
532+ pytest .param (["1" , "3" , "5-7" ], True , id = "list-mixed" ),
533+ ],
534+ )
535+ async def test_live_async_png_page_range_variants (
536+ pdfrest_api_key : str ,
537+ pdfrest_live_base_url : str ,
538+ uploaded_20_page_pdf : PdfRestFile ,
539+ page_range : Any ,
540+ expect_success : bool ,
541+ request : pytest .FixtureRequest ,
542+ ) -> None :
543+ case_id = request .node .callspec .id
544+ async with AsyncPdfRestClient (
545+ api_key = pdfrest_api_key ,
546+ base_url = pdfrest_live_base_url ,
547+ ) as client :
548+ info = await client .query_pdf_info (uploaded_20_page_pdf )
549+
550+ assert info .page_count == 20
551+ assert str (info .input_id ) == str (uploaded_20_page_pdf .id )
552+ assert info .filename is None or info .filename .endswith (".pdf" )
553+
554+ if expect_success :
555+ response = await client .convert_to_png (
556+ uploaded_20_page_pdf ,
557+ output_prefix = f"live-async-range-{ case_id } " ,
558+ page_range = page_range ,
559+ )
560+
561+ expected_pages = _expand_page_selection (page_range , total_pages = 20 )
562+ assert len (response .output_files ) == len (expected_pages )
563+ assert any (
564+ file_info .name .endswith (".png" ) for file_info in response .output_files
565+ )
566+ assert all (
567+ file_info .type == "image/png" and file_info .size > 0
568+ for file_info in response .output_files
569+ )
570+ assert str (response .input_id ) == str (uploaded_20_page_pdf .id )
571+ else :
572+ with pytest .raises (PdfRestApiError , match = r"(?i)page" ):
573+ await client .convert_to_png (
574+ uploaded_20_page_pdf ,
575+ output_prefix = f"live-async-range-{ case_id } " ,
576+ extra_body = {"page_range" : page_range },
577+ )
578+
579+
397580@pytest .mark .parametrize (
398581 "page_override" ,
399582 [
@@ -431,6 +614,42 @@ def test_live_png_page_range_invalid_overrides(
431614 )
432615
433616
617+ @pytest .mark .asyncio
618+ @pytest .mark .parametrize (
619+ "page_override" ,
620+ [
621+ pytest .param ("0" , id = "zero" ),
622+ pytest .param ("last-0" , id = "range-with-zero" ),
623+ pytest .param ("7-3" , id = "descending-range" ),
624+ pytest .param ("even" , id = "even" ),
625+ pytest .param ("odd" , id = "odd" ),
626+ pytest .param ("odd,even" , id = "odd-even" ),
627+ ],
628+ )
629+ async def test_live_async_png_page_range_invalid_overrides (
630+ pdfrest_api_key : str ,
631+ pdfrest_live_base_url : str ,
632+ uploaded_20_page_pdf : PdfRestFile ,
633+ page_override : str ,
634+ request : pytest .FixtureRequest ,
635+ ) -> None :
636+ case_id = request .node .callspec .id
637+ async with AsyncPdfRestClient (
638+ api_key = pdfrest_api_key ,
639+ base_url = pdfrest_live_base_url ,
640+ ) as client :
641+ with pytest .raises (
642+ PdfRestApiError ,
643+ match = r"There was an issue processing your file\. Validate all fields and try again\." ,
644+ ):
645+ await client .convert_to_png (
646+ uploaded_20_page_pdf ,
647+ output_prefix = f"live-async-range-invalid-{ case_id } " ,
648+ page_range = "1" ,
649+ extra_body = {"pages" : page_override },
650+ )
651+
652+
434653def _expand_page_selection (
435654 selection : Any ,
436655 * ,
0 commit comments