@@ -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+
657704def test_sign_pdf_request_customization (
658705 monkeypatch : pytest .MonkeyPatch ,
659706) -> None :
0 commit comments