Skip to content

Commit 185dbd9

Browse files
tests: Strengthen live password-suite response assertions
- add shared `assert_pdf_file_response` helpers to live encryption and permissions-password suites - assert additional response attributes on success paths, including file size, `.pdf` suffix, and `response.warning is None` - keep existing MIME type, output-prefix, and input-id checks while reducing repeated assertion blocks - align live assertions with repository testing guidelines for richer server-response verification Assisted-by: Codex
1 parent ebaad21 commit 185dbd9

2 files changed

Lines changed: 94 additions & 62 deletions

File tree

tests/live/test_live_encrypt_pdf.py

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
8-
from pdfrest.models import PdfRestFile
8+
from pdfrest.models import PdfRestFile, PdfRestFileBasedResponse
99

1010
from ..resources import get_test_resource_path
1111

@@ -14,6 +14,22 @@ def make_password(label: str) -> str:
1414
return f"{label}-{uuid4().hex}"
1515

1616

17+
def assert_pdf_file_response(
18+
response: PdfRestFileBasedResponse,
19+
*,
20+
output_prefix: str,
21+
input_file: PdfRestFile,
22+
) -> None:
23+
assert response.output_files
24+
output_file = response.output_file
25+
assert output_file.type == "application/pdf"
26+
assert output_file.name.startswith(output_prefix)
27+
assert output_file.name.endswith(".pdf")
28+
assert output_file.size > 0
29+
assert response.warning is None
30+
assert str(response.input_id) == str(input_file.id)
31+
32+
1733
@pytest.fixture(scope="module")
1834
def uploaded_pdf_for_encrypt(
1935
pdfrest_api_key: str,
@@ -42,11 +58,11 @@ def test_live_add_open_password(
4258
output="live-encrypted",
4359
)
4460

45-
assert response.output_files
46-
output_file = response.output_file
47-
assert output_file.type == "application/pdf"
48-
assert output_file.name.startswith("live-encrypted")
49-
assert str(response.input_id) == str(uploaded_pdf_for_encrypt.id)
61+
assert_pdf_file_response(
62+
response,
63+
output_prefix="live-encrypted",
64+
input_file=uploaded_pdf_for_encrypt,
65+
)
5066

5167

5268
@pytest.mark.asyncio
@@ -65,11 +81,11 @@ async def test_live_async_add_open_password(
6581
output="async-live-encrypted",
6682
)
6783

68-
assert response.output_files
69-
output_file = response.output_file
70-
assert output_file.type == "application/pdf"
71-
assert output_file.name.startswith("async-live-encrypted")
72-
assert str(response.input_id) == str(uploaded_pdf_for_encrypt.id)
84+
assert_pdf_file_response(
85+
response,
86+
output_prefix="async-live-encrypted",
87+
input_file=uploaded_pdf_for_encrypt,
88+
)
7389

7490

7591
def test_live_change_open_password(
@@ -94,11 +110,11 @@ def test_live_change_open_password(
94110
output="live-open-new",
95111
)
96112

97-
assert response.output_files
98-
output_file = response.output_file
99-
assert output_file.name.startswith("live-open-new")
100-
assert output_file.type == "application/pdf"
101-
assert str(response.input_id) == str(restricted.id)
113+
assert_pdf_file_response(
114+
response,
115+
output_prefix="live-open-new",
116+
input_file=restricted,
117+
)
102118

103119

104120
@pytest.mark.asyncio
@@ -126,11 +142,11 @@ async def test_live_async_change_open_password(
126142
output="async-live-open-new",
127143
)
128144

129-
assert response.output_files
130-
output_file = response.output_file
131-
assert output_file.name.startswith("async-live-open-new")
132-
assert output_file.type == "application/pdf"
133-
assert str(response.input_id) == str(restricted.id)
145+
assert_pdf_file_response(
146+
response,
147+
output_prefix="async-live-open-new",
148+
input_file=restricted,
149+
)
134150

135151

136152
def test_live_remove_open_password(
@@ -154,11 +170,11 @@ def test_live_remove_open_password(
154170
output="live-open-removed",
155171
)
156172

157-
assert response.output_files
158-
output_file = response.output_file
159-
assert output_file.type == "application/pdf"
160-
assert output_file.name.startswith("live-open-removed")
161-
assert str(response.input_id) == str(restricted.id)
173+
assert_pdf_file_response(
174+
response,
175+
output_prefix="live-open-removed",
176+
input_file=restricted,
177+
)
162178

163179

164180
@pytest.mark.asyncio
@@ -185,11 +201,11 @@ async def test_live_async_remove_open_password(
185201
output="async-live-open-removed",
186202
)
187203

188-
assert response.output_files
189-
output_file = response.output_file
190-
assert output_file.type == "application/pdf"
191-
assert output_file.name.startswith("async-live-open-removed")
192-
assert str(response.input_id) == str(restricted.id)
204+
assert_pdf_file_response(
205+
response,
206+
output_prefix="async-live-open-removed",
207+
input_file=restricted,
208+
)
193209

194210

195211
def test_live_remove_open_password_invalid_password(

tests/live/test_live_permissions_password.py

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from pdfrest import AsyncPdfRestClient, PdfRestApiError, PdfRestClient
9-
from pdfrest.models import PdfRestFile
9+
from pdfrest.models import PdfRestFile, PdfRestFileBasedResponse
1010
from pdfrest.types import PdfRestriction
1111

1212
from ..resources import get_test_resource_path
@@ -16,6 +16,22 @@ def make_password(label: str) -> str:
1616
return f"{label}-{uuid4().hex}"
1717

1818

19+
def assert_pdf_file_response(
20+
response: PdfRestFileBasedResponse,
21+
*,
22+
output_prefix: str,
23+
input_file: PdfRestFile,
24+
) -> None:
25+
assert response.output_files
26+
output_file = response.output_file
27+
assert output_file.type == "application/pdf"
28+
assert output_file.name.startswith(output_prefix)
29+
assert output_file.name.endswith(".pdf")
30+
assert output_file.size > 0
31+
assert response.warning is None
32+
assert str(response.input_id) == str(input_file.id)
33+
34+
1935
PDF_RESTRICTIONS: tuple[PdfRestriction, ...] = cast(
2036
tuple[PdfRestriction, ...], get_args(PdfRestriction)
2137
)
@@ -56,11 +72,11 @@ def test_live_add_permissions_password(
5672
output="live-restrict",
5773
)
5874

59-
assert response.output_files
60-
output_file = response.output_file
61-
assert output_file.type == "application/pdf"
62-
assert output_file.name.startswith("live-restrict")
63-
assert str(response.input_id) == str(uploaded_pdf_for_permissions.id)
75+
assert_pdf_file_response(
76+
response,
77+
output_prefix="live-restrict",
78+
input_file=uploaded_pdf_for_permissions,
79+
)
6480

6581

6682
@pytest.mark.asyncio
@@ -83,11 +99,11 @@ async def test_live_async_add_permissions_password(
8399
output="async-restrict",
84100
)
85101

86-
assert response.output_files
87-
output_file = response.output_file
88-
assert output_file.type == "application/pdf"
89-
assert output_file.name.startswith("async-restrict")
90-
assert str(response.input_id) == str(uploaded_pdf_for_permissions.id)
102+
assert_pdf_file_response(
103+
response,
104+
output_prefix="async-restrict",
105+
input_file=uploaded_pdf_for_permissions,
106+
)
91107

92108

93109
def test_live_change_permissions_password(
@@ -116,11 +132,11 @@ def test_live_change_permissions_password(
116132
output="live-restrict-new",
117133
)
118134

119-
assert response.output_files
120-
output_file = response.output_file
121-
assert output_file.name.startswith("live-restrict-new")
122-
assert output_file.type == "application/pdf"
123-
assert str(response.input_id) == str(restricted_file.id)
135+
assert_pdf_file_response(
136+
response,
137+
output_prefix="live-restrict-new",
138+
input_file=restricted_file,
139+
)
124140

125141

126142
@pytest.mark.asyncio
@@ -150,11 +166,11 @@ async def test_live_async_change_permissions_password(
150166
output="async-live-restrict-new",
151167
)
152168

153-
assert response.output_files
154-
output_file = response.output_file
155-
assert output_file.name.startswith("async-live-restrict-new")
156-
assert output_file.type == "application/pdf"
157-
assert str(response.input_id) == str(restricted_file.id)
169+
assert_pdf_file_response(
170+
response,
171+
output_prefix="async-live-restrict-new",
172+
input_file=restricted_file,
173+
)
158174

159175

160176
def test_live_remove_permissions_password(
@@ -180,11 +196,11 @@ def test_live_remove_permissions_password(
180196
output="live-removed",
181197
)
182198

183-
assert response.output_files
184-
output_file = response.output_file
185-
assert output_file.name.startswith("live-removed")
186-
assert output_file.type == "application/pdf"
187-
assert str(response.input_id) == str(restricted_file.id)
199+
assert_pdf_file_response(
200+
response,
201+
output_prefix="live-removed",
202+
input_file=restricted_file,
203+
)
188204

189205

190206
@pytest.mark.asyncio
@@ -211,11 +227,11 @@ async def test_live_async_remove_permissions_password(
211227
output="async-live-removed",
212228
)
213229

214-
assert response.output_files
215-
output_file = response.output_file
216-
assert output_file.name.startswith("async-live-removed")
217-
assert output_file.type == "application/pdf"
218-
assert str(response.input_id) == str(restricted_file.id)
230+
assert_pdf_file_response(
231+
response,
232+
output_prefix="async-live-removed",
233+
input_file=restricted_file,
234+
)
219235

220236

221237
def test_live_remove_permissions_password_invalid_password(

0 commit comments

Comments
 (0)