@@ -136,32 +136,109 @@ def test_live_redaction_preview_and_apply_multiple(
136136
137137
138138@pytest .mark .asyncio
139- async def test_live_async_redaction_preview_and_apply (
139+ @pytest .mark .parametrize (
140+ "instructions" ,
141+ [
142+ pytest .param (
143+ [
144+ {
145+ "type" : "literal" ,
146+ "value" : "The quick brown fox jumped over the lazy dog." ,
147+ },
148+ {"type" : "regex" , "value" : r"\b\d{3}-\d{2}-\d{4}\b" },
149+ ],
150+ id = "literal-and-regex" ,
151+ ),
152+ pytest .param (
153+ [
154+ {"type" : "preset" , "value" : "email" },
155+ {"type" : "preset" , "value" : "phone_number" },
156+ ],
157+ id = "preset-email-and-phone" ,
158+ ),
159+ pytest .param (
160+ [
161+ {"type" : "preset" , "value" : "credit_card" },
162+ {"type" : "preset" , "value" : "bank_routing_number" },
163+ {"type" : "preset" , "value" : "swift_bic_number" },
164+ ],
165+ id = "multiple-presets" ,
166+ ),
167+ ],
168+ )
169+ async def test_live_async_redaction_preview_and_apply_multiple (
140170 pdfrest_api_key : str ,
141171 pdfrest_live_base_url : str ,
142172 uploaded_pdf_for_redaction : PdfRestFile ,
173+ instructions : list [PdfRedactionInstruction ],
143174) -> None :
144175 async with AsyncPdfRestClient (
145176 api_key = pdfrest_api_key ,
146177 base_url = pdfrest_live_base_url ,
147178 ) as client :
148179 preview = await client .preview_redactions (
149180 uploaded_pdf_for_redaction ,
150- redactions = [{ "type" : "literal" , "value" : "quick brown fox" }] ,
151- output = "async- redaction-preview" ,
181+ redactions = instructions ,
182+ output = "redaction-preview-multi " ,
152183 )
153184
185+ assert preview .output_files
154186 preview_file = preview .output_files [0 ]
155187 applied = await client .apply_redactions (
156188 preview_file ,
157- output = "async-redaction-final" ,
189+ output = "redaction-final-multi" ,
190+ )
191+
192+ final_file = applied .output_files [0 ]
193+ assert final_file .name .endswith ("redaction-final-multi.pdf" )
194+ assert final_file .type == "application/pdf"
195+
196+
197+ @pytest .mark .asyncio
198+ @pytest .mark .parametrize (
199+ "instruction" ,
200+ [
201+ pytest .param (
202+ {
203+ "type" : "literal" ,
204+ "value" : "The quick brown fox jumped over the lazy dog." ,
205+ },
206+ id = "literal" ,
207+ ),
208+ pytest .param ({"type" : "regex" , "value" : r"\b\d{3}-\d{2}-\d{4}\b" }, id = "regex" ),
209+ * [
210+ pytest .param ({"type" : "preset" , "value" : preset }, id = f"preset-{ preset } " )
211+ for preset in get_args (PdfRedactionPreset )
212+ ],
213+ ],
214+ )
215+ async def test_live_async_redaction_preview_and_apply_single (
216+ pdfrest_api_key : str ,
217+ pdfrest_live_base_url : str ,
218+ uploaded_pdf_for_redaction : PdfRestFile ,
219+ instruction : PdfRedactionInstruction ,
220+ ) -> None :
221+ async with AsyncPdfRestClient (
222+ api_key = pdfrest_api_key ,
223+ base_url = pdfrest_live_base_url ,
224+ ) as client :
225+ preview = await client .preview_redactions (
226+ uploaded_pdf_for_redaction ,
227+ redactions = [instruction ],
228+ output = "redaction-preview" ,
229+ )
230+
231+ preview_file = preview .output_files [0 ]
232+ applied = await client .apply_redactions (
233+ preview_file ,
234+ output = "redaction-final" ,
158235 )
159236
160237 assert preview .output_files
161- assert preview_file .name .endswith ("async- redaction-preview.pdf" )
238+ assert preview_file .name .endswith ("redaction-preview.pdf" )
162239 assert applied .output_files
163240 final_file = applied .output_files [0 ]
164- assert final_file .name .endswith ("async- redaction-final.pdf" )
241+ assert final_file .name .endswith ("redaction-final.pdf" )
165242 assert final_file .type == "application/pdf"
166243
167244
@@ -206,18 +283,42 @@ def test_live_redactions_invalid_payloads(
206283
207284
208285@pytest .mark .asyncio
286+ @pytest .mark .parametrize (
287+ "extra_body" ,
288+ [
289+ pytest .param ({"redactions" : "invalid" }, id = "invalid-redactions" ),
290+ pytest .param ({"rgb_color" : "-1,-1,-1" }, id = "invalid-rgb" ),
291+ ],
292+ )
209293async def test_live_async_redactions_invalid_payloads (
210294 pdfrest_api_key : str ,
211295 pdfrest_live_base_url : str ,
212296 uploaded_pdf_for_redaction : PdfRestFile ,
297+ extra_body : dict [str , object ],
213298) -> None :
214299 async with AsyncPdfRestClient (
215300 api_key = pdfrest_api_key ,
216301 base_url = pdfrest_live_base_url ,
217302 ) as client :
218- with pytest .raises (PdfRestApiError , match = r"(?i)rgb" ):
219- await client .preview_redactions (
303+ if "redactions" in extra_body :
304+ with pytest .raises (
305+ PdfRestApiError ,
306+ match = (
307+ r"The JSON data provided is not properly formatted\. Please check "
308+ r"your syntax and try again\."
309+ ),
310+ ):
311+ await client .preview_redactions (
312+ uploaded_pdf_for_redaction ,
313+ redactions = [{"type" : "literal" , "value" : "placeholder" }],
314+ extra_body = extra_body ,
315+ )
316+ else :
317+ preview = await client .preview_redactions (
220318 uploaded_pdf_for_redaction ,
221319 redactions = [{"type" : "literal" , "value" : "placeholder" }],
222- extra_body = { "rgb_color" : "-1,-1,-1" } ,
320+ extra_body = extra_body ,
223321 )
322+ preview_file = preview .output_files [0 ]
323+ with pytest .raises (PdfRestApiError , match = r"(?i)rgb" ):
324+ await client .apply_redactions (preview_file , extra_body = extra_body )
0 commit comments