Skip to content

Commit bf69686

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 0e78645 commit bf69686

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
@@ -125,6 +125,47 @@ def test_live_sign_pdf_with_pfx_credentials(
125125
assert str(uploaded_pdf_for_signing.id) in response.input_ids
126126

127127

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

0 commit comments

Comments
 (0)