@@ -76,6 +76,20 @@ def build_unrestrict_payload(
7676 ).model_dump (mode = "json" , by_alias = True , exclude_none = True , exclude_unset = True )
7777
7878
79+ def assert_pdf_file_response (
80+ response : PdfRestFileBasedResponse , * , expected_name : str , input_file : PdfRestFile
81+ ) -> None :
82+ assert isinstance (response , PdfRestFileBasedResponse )
83+ output_file = response .output_file
84+ assert output_file .name == expected_name
85+ assert output_file .type == "application/pdf"
86+ assert output_file .size > 0
87+ output_url = str (output_file .url )
88+ assert f"/resource/{ output_file .id } " in output_url
89+ assert response .warning is None
90+ assert str (response .input_id ) == str (input_file .id )
91+
92+
7993@pytest .mark .parametrize (
8094 "restrictions" ,
8195 [
@@ -139,10 +153,11 @@ def handler(request: httpx.Request) -> httpx.Response:
139153 )
140154
141155 assert seen == {"post" : 1 , "get" : 1 }
142- assert isinstance (response , PdfRestFileBasedResponse )
143- assert response .output_file .name == "restricted.pdf"
144- assert response .output_file .type == "application/pdf"
145- assert str (response .input_id ) == str (input_file .id )
156+ assert_pdf_file_response (
157+ response ,
158+ expected_name = "restricted.pdf" ,
159+ input_file = input_file ,
160+ )
146161
147162
148163def test_add_permissions_password_request_customization (
@@ -202,8 +217,11 @@ def handler(request: httpx.Request) -> httpx.Response:
202217 timeout = 0.55 ,
203218 )
204219
205- assert isinstance (response , PdfRestFileBasedResponse )
206- assert response .output_file .name == "custom-restricted.pdf"
220+ assert_pdf_file_response (
221+ response ,
222+ expected_name = "custom-restricted.pdf" ,
223+ input_file = input_file ,
224+ )
207225 timeout_value = captured_timeout ["value" ]
208226 assert timeout_value is not None
209227 if isinstance (timeout_value , dict ):
@@ -275,8 +293,11 @@ def handler(request: httpx.Request) -> httpx.Response:
275293 timeout = 0.77 ,
276294 )
277295
278- assert isinstance (response , PdfRestFileBasedResponse )
279- assert response .output_file .name == "rotated.pdf"
296+ assert_pdf_file_response (
297+ response ,
298+ expected_name = "rotated.pdf" ,
299+ input_file = input_file ,
300+ )
280301 timeout_value = captured_timeout ["value" ]
281302 assert timeout_value is not None
282303 if isinstance (timeout_value , dict ):
@@ -335,9 +356,11 @@ def handler(request: httpx.Request) -> httpx.Response:
335356 )
336357
337358 assert seen == {"post" : 1 , "get" : 1 }
338- assert isinstance (response , PdfRestFileBasedResponse )
339- assert response .output_file .name == "clean.pdf"
340- assert response .output_file .type == "application/pdf"
359+ assert_pdf_file_response (
360+ response ,
361+ expected_name = "clean.pdf" ,
362+ input_file = input_file ,
363+ )
341364
342365
343366def test_remove_permissions_password_request_customization (
@@ -398,8 +421,11 @@ def handler(request: httpx.Request) -> httpx.Response:
398421 timeout = 0.69 ,
399422 )
400423
401- assert isinstance (response , PdfRestFileBasedResponse )
402- assert response .output_file .name == "clean-custom.pdf"
424+ assert_pdf_file_response (
425+ response ,
426+ expected_name = "clean-custom.pdf" ,
427+ input_file = input_file ,
428+ )
403429 timeout_value = captured_timeout ["value" ]
404430 assert timeout_value is not None
405431 if isinstance (timeout_value , dict ):
@@ -469,10 +495,11 @@ def handler(request: httpx.Request) -> httpx.Response:
469495 )
470496
471497 assert seen == {"post" : 1 , "get" : 1 }
472- assert isinstance (response , PdfRestFileBasedResponse )
473- assert response .output_file .name == "restricted.pdf"
474- assert response .output_file .type == "application/pdf"
475- assert str (response .input_id ) == str (input_file .id )
498+ assert_pdf_file_response (
499+ response ,
500+ expected_name = "restricted.pdf" ,
501+ input_file = input_file ,
502+ )
476503
477504
478505@pytest .mark .asyncio
@@ -534,8 +561,11 @@ def handler(request: httpx.Request) -> httpx.Response:
534561 timeout = 0.66 ,
535562 )
536563
537- assert isinstance (response , PdfRestFileBasedResponse )
538- assert response .output_file .name == "async-restricted.pdf"
564+ assert_pdf_file_response (
565+ response ,
566+ expected_name = "async-restricted.pdf" ,
567+ input_file = input_file ,
568+ )
539569 timeout_value = captured_timeout ["value" ]
540570 assert timeout_value is not None
541571 if isinstance (timeout_value , dict ):
@@ -608,8 +638,11 @@ def handler(request: httpx.Request) -> httpx.Response:
608638 timeout = 0.88 ,
609639 )
610640
611- assert isinstance (response , PdfRestFileBasedResponse )
612- assert response .output_file .name == "async-rotated.pdf"
641+ assert_pdf_file_response (
642+ response ,
643+ expected_name = "async-rotated.pdf" ,
644+ input_file = input_file ,
645+ )
613646 timeout_value = captured_timeout ["value" ]
614647 assert timeout_value is not None
615648 if isinstance (timeout_value , dict ):
@@ -662,8 +695,11 @@ def handler(request: httpx.Request) -> httpx.Response:
662695 current_permissions_password = current_password ,
663696 )
664697
665- assert isinstance (response , PdfRestFileBasedResponse )
666- assert response .output_file .name == "async-clean.pdf"
698+ assert_pdf_file_response (
699+ response ,
700+ expected_name = "async-clean.pdf" ,
701+ input_file = input_file ,
702+ )
667703
668704
669705@pytest .mark .asyncio
@@ -725,8 +761,11 @@ def handler(request: httpx.Request) -> httpx.Response:
725761 timeout = 0.73 ,
726762 )
727763
728- assert isinstance (response , PdfRestFileBasedResponse )
729- assert response .output_file .name == "async-clean-custom.pdf"
764+ assert_pdf_file_response (
765+ response ,
766+ expected_name = "async-clean-custom.pdf" ,
767+ input_file = input_file ,
768+ )
730769 timeout_value = captured_timeout ["value" ]
731770 assert timeout_value is not None
732771 if isinstance (timeout_value , dict ):
0 commit comments