Skip to content

Commit 988817d

Browse files
tests: Strengthen password-suite response assertions with URL checks
Assisted-by: Codex
1 parent 185dbd9 commit 988817d

4 files changed

Lines changed: 122 additions & 44 deletions

File tree

tests/live/test_live_encrypt_pdf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def assert_pdf_file_response(
2626
assert output_file.name.startswith(output_prefix)
2727
assert output_file.name.endswith(".pdf")
2828
assert output_file.size > 0
29+
output_url = str(output_file.url)
30+
assert f"/resource/{output_file.id}" in output_url
2931
assert response.warning is None
3032
assert str(response.input_id) == str(input_file.id)
3133

tests/live/test_live_permissions_password.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def assert_pdf_file_response(
2828
assert output_file.name.startswith(output_prefix)
2929
assert output_file.name.endswith(".pdf")
3030
assert output_file.size > 0
31+
output_url = str(output_file.url)
32+
assert f"/resource/{output_file.id}" in output_url
3133
assert response.warning is None
3234
assert str(response.input_id) == str(input_file.id)
3335

tests/test_encrypt_pdf.py

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ def build_decrypt_payload(
7373
).model_dump(mode="json", by_alias=True, exclude_none=True, exclude_unset=True)
7474

7575

76+
def assert_pdf_file_response(
77+
response: PdfRestFileBasedResponse, *, expected_name: str, input_file: PdfRestFile
78+
) -> None:
79+
assert isinstance(response, PdfRestFileBasedResponse)
80+
output_file = response.output_file
81+
assert output_file.name == expected_name
82+
assert output_file.type == "application/pdf"
83+
assert output_file.size > 0
84+
output_url = str(output_file.url)
85+
assert f"/resource/{output_file.id}" in output_url
86+
assert response.warning is None
87+
assert str(response.input_id) == str(input_file.id)
88+
89+
7690
@pytest.mark.parametrize(
7791
"permissions_password",
7892
[
@@ -132,10 +146,11 @@ def handler(request: httpx.Request) -> httpx.Response:
132146
)
133147

134148
assert seen == {"post": 1, "get": 1}
135-
assert isinstance(response, PdfRestFileBasedResponse)
136-
assert response.output_file.name == "encrypted.pdf"
137-
assert response.output_file.type == "application/pdf"
138-
assert str(response.input_id) == str(input_file.id)
149+
assert_pdf_file_response(
150+
response,
151+
expected_name="encrypted.pdf",
152+
input_file=input_file,
153+
)
139154

140155

141156
def test_change_open_password_request_customization(
@@ -199,8 +214,11 @@ def handler(request: httpx.Request) -> httpx.Response:
199214
timeout=0.77,
200215
)
201216

202-
assert isinstance(response, PdfRestFileBasedResponse)
203-
assert response.output_file.name == "rotated-open.pdf"
217+
assert_pdf_file_response(
218+
response,
219+
expected_name="rotated-open.pdf",
220+
input_file=input_file,
221+
)
204222
timeout_value = captured_timeout["value"]
205223
assert timeout_value is not None
206224
if isinstance(timeout_value, dict):
@@ -257,9 +275,11 @@ def handler(request: httpx.Request) -> httpx.Response:
257275
)
258276

259277
assert seen == {"post": 1, "get": 1}
260-
assert isinstance(response, PdfRestFileBasedResponse)
261-
assert response.output_file.name == "decrypted.pdf"
262-
assert response.output_file.type == "application/pdf"
278+
assert_pdf_file_response(
279+
response,
280+
expected_name="decrypted.pdf",
281+
input_file=input_file,
282+
)
263283

264284

265285
def test_remove_open_password_request_customization(
@@ -320,8 +340,11 @@ def handler(request: httpx.Request) -> httpx.Response:
320340
timeout=0.59,
321341
)
322342

323-
assert isinstance(response, PdfRestFileBasedResponse)
324-
assert response.output_file.name == "decrypted-custom.pdf"
343+
assert_pdf_file_response(
344+
response,
345+
expected_name="decrypted-custom.pdf",
346+
input_file=input_file,
347+
)
325348
timeout_value = captured_timeout["value"]
326349
assert timeout_value is not None
327350
if isinstance(timeout_value, dict):
@@ -389,8 +412,11 @@ def handler(request: httpx.Request) -> httpx.Response:
389412
timeout=0.66,
390413
)
391414

392-
assert isinstance(response, PdfRestFileBasedResponse)
393-
assert response.output_file.name == "async-encrypted.pdf"
415+
assert_pdf_file_response(
416+
response,
417+
expected_name="async-encrypted.pdf",
418+
input_file=input_file,
419+
)
394420
timeout_value = captured_timeout["value"]
395421
assert timeout_value is not None
396422
if isinstance(timeout_value, dict):
@@ -451,8 +477,11 @@ def handler(request: httpx.Request) -> httpx.Response:
451477
output="async-rotated-open",
452478
)
453479

454-
assert isinstance(response, PdfRestFileBasedResponse)
455-
assert response.output_file.name == "async-rotated-open.pdf"
480+
assert_pdf_file_response(
481+
response,
482+
expected_name="async-rotated-open.pdf",
483+
input_file=input_file,
484+
)
456485

457486

458487
@pytest.mark.asyncio
@@ -499,8 +528,11 @@ def handler(request: httpx.Request) -> httpx.Response:
499528
current_open_password=current_password,
500529
)
501530

502-
assert isinstance(response, PdfRestFileBasedResponse)
503-
assert response.output_file.name == "async-decrypted.pdf"
531+
assert_pdf_file_response(
532+
response,
533+
expected_name="async-decrypted.pdf",
534+
input_file=input_file,
535+
)
504536

505537

506538
@pytest.mark.asyncio
@@ -562,8 +594,11 @@ def handler(request: httpx.Request) -> httpx.Response:
562594
timeout=0.63,
563595
)
564596

565-
assert isinstance(response, PdfRestFileBasedResponse)
566-
assert response.output_file.name == "async-decrypted-custom.pdf"
597+
assert_pdf_file_response(
598+
response,
599+
expected_name="async-decrypted-custom.pdf",
600+
input_file=input_file,
601+
)
567602
timeout_value = captured_timeout["value"]
568603
assert timeout_value is not None
569604
if isinstance(timeout_value, dict):

tests/test_permissions_password.py

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

148163
def 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

343366
def 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

Comments
 (0)