Skip to content

Commit 6d004b8

Browse files
tests: Add tests for invalid signature type rejection
- Added `test_sign_pdf_rejects_invalid_signature_type_literal` to validate rejection of unsupported signature types for synchronous clients. - Added `test_async_sign_pdf_rejects_invalid_signature_type_literal` for async client behavior validation. - Ensures consistent error handling for unsupported configurations. Assisted-by: Codex
1 parent 8a09b43 commit 6d004b8

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

tests/test_sign_pdf.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,53 @@ def handler(request: httpx.Request) -> httpx.Response:
654654
assert response.output_file.name == f"literal-async-{signature_type}.pdf"
655655

656656

657+
def test_sign_pdf_rejects_invalid_signature_type_literal(
658+
monkeypatch: pytest.MonkeyPatch,
659+
) -> None:
660+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
661+
input_file = make_pdf_file(PdfRestFileID.generate())
662+
pfx_file = make_pfx_file(str(PdfRestFileID.generate()))
663+
passphrase_file = make_passphrase_file(str(PdfRestFileID.generate()))
664+
transport = httpx.MockTransport(lambda request: (_ for _ in ()).throw(RuntimeError))
665+
666+
with (
667+
PdfRestClient(api_key=VALID_API_KEY, transport=transport) as client,
668+
pytest.raises(ValidationError, match="Input should be 'new' or 'existing'"),
669+
):
670+
client.sign_pdf(
671+
input_file,
672+
signature_configuration={
673+
"type": "unexpected",
674+
"location": make_signature_location(),
675+
},
676+
credentials={"pfx": pfx_file, "passphrase": passphrase_file},
677+
)
678+
679+
680+
@pytest.mark.asyncio
681+
async def test_async_sign_pdf_rejects_invalid_signature_type_literal(
682+
monkeypatch: pytest.MonkeyPatch,
683+
) -> None:
684+
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
685+
input_file = make_pdf_file(PdfRestFileID.generate())
686+
pfx_file = make_pfx_file(str(PdfRestFileID.generate()))
687+
passphrase_file = make_passphrase_file(str(PdfRestFileID.generate()))
688+
transport = httpx.MockTransport(lambda request: (_ for _ in ()).throw(RuntimeError))
689+
690+
async with AsyncPdfRestClient(api_key=ASYNC_API_KEY, transport=transport) as client:
691+
with pytest.raises(
692+
ValidationError, match="Input should be 'new' or 'existing'"
693+
):
694+
await client.sign_pdf(
695+
input_file,
696+
signature_configuration={
697+
"type": "unexpected",
698+
"location": make_signature_location(),
699+
},
700+
credentials={"pfx": pfx_file, "passphrase": passphrase_file},
701+
)
702+
703+
657704
def test_sign_pdf_request_customization(
658705
monkeypatch: pytest.MonkeyPatch,
659706
) -> None:

0 commit comments

Comments
 (0)