Skip to content

Commit 88cfe35

Browse files
tests/live: Add test for signing PDF with existing signature field
- Introduced `test_live_sign_pdf_with_existing_signature_field` to verify signing a PDF with an existing signature field. - Tested both "new" and "existing" signature types for compatibility. - Ensured proper validation of output file type, name, and input IDs. Assisted-by: Codex
1 parent fecb394 commit 88cfe35

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

tests/live/test_live_sign_pdf.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,47 @@ def test_live_sign_pdf_with_pfx_credentials(
124124
assert str(uploaded_pdf_for_signing.id) in response.input_ids
125125

126126

127+
def test_live_sign_pdf_with_existing_signature_field(
128+
pdfrest_api_key: str,
129+
pdfrest_live_base_url: str,
130+
uploaded_pdf_for_signing: PdfRestFile,
131+
uploaded_certificate: PdfRestFile,
132+
uploaded_private_key: PdfRestFile,
133+
) -> None:
134+
signature_name = "sdk-existing-live"
135+
with PdfRestClient(
136+
api_key=pdfrest_api_key,
137+
base_url=pdfrest_live_base_url,
138+
) as client:
139+
first_response = client.sign_pdf(
140+
uploaded_pdf_for_signing,
141+
signature_configuration={
142+
"type": "new",
143+
"name": signature_name,
144+
"location": make_signature_location(),
145+
},
146+
credentials={
147+
"certificate": uploaded_certificate,
148+
"private_key": uploaded_private_key,
149+
},
150+
output="live-signed-new-for-existing",
151+
)
152+
153+
existing_response = client.sign_pdf(
154+
first_response.output_file,
155+
signature_configuration={"type": "existing", "name": signature_name},
156+
credentials={
157+
"certificate": uploaded_certificate,
158+
"private_key": uploaded_private_key,
159+
},
160+
output="live-signed-existing",
161+
)
162+
163+
assert existing_response.output_file.type == "application/pdf"
164+
assert existing_response.output_file.name == "live-signed-existing.pdf"
165+
assert str(first_response.output_file.id) in existing_response.input_ids
166+
167+
127168
@pytest.mark.asyncio
128169
async def test_live_async_sign_pdf_with_certificate(
129170
pdfrest_api_key: str,
@@ -137,11 +178,7 @@ async def test_live_async_sign_pdf_with_certificate(
137178
"type": "new",
138179
"name": "live-async-signature",
139180
"logo_opacity": 0.5,
140-
"location": {
141-
"bottom_left": {"x": 1, "y": 1},
142-
"top_right": {"x": 217, "y": 73},
143-
"page": 1,
144-
},
181+
"location": make_signature_location(),
145182
}
146183
async with AsyncPdfRestClient(
147184
api_key=pdfrest_api_key,

0 commit comments

Comments
 (0)