Skip to content

Commit 3d8f31b

Browse files
watermark-pdf: Add live negative boundary tests for numeric fields
Assisted-by: Codex
1 parent 74f7ccb commit 3d8f31b

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

tests/live/test_live_watermark_pdf.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,136 @@ async def test_live_async_watermark_pdf_invalid_file_id(
322322
watermark_text="AsyncInvalid",
323323
extra_body={"id": "00000000-0000-0000-0000-000000000000"},
324324
)
325+
326+
327+
@pytest.mark.parametrize(
328+
("extra_body", "error_match"),
329+
[
330+
pytest.param(
331+
{"opacity": "1.01"},
332+
r"(?i)(opacity|range)",
333+
id="opacity-above-max",
334+
),
335+
pytest.param(
336+
{"opacity": "-0.01"},
337+
r"(?i)(opacity|range)",
338+
id="opacity-below-min",
339+
),
340+
pytest.param(
341+
{"text_size": "101"},
342+
r"(?i)(text_size|size|range)",
343+
id="text-size-above-max",
344+
),
345+
pytest.param(
346+
{"text_size": "4"},
347+
r"(?i)(text_size|size|range)",
348+
id="text-size-below-min",
349+
),
350+
],
351+
)
352+
def test_live_watermark_pdf_text_invalid_numeric_bounds(
353+
pdfrest_api_key: str,
354+
pdfrest_live_base_url: str,
355+
uploaded_pdf_for_watermark: PdfRestFile,
356+
extra_body: dict[str, str],
357+
error_match: str,
358+
) -> None:
359+
with (
360+
PdfRestClient(
361+
api_key=pdfrest_api_key,
362+
base_url=pdfrest_live_base_url,
363+
) as client,
364+
pytest.raises(PdfRestApiError, match=error_match),
365+
):
366+
client.watermark_pdf_with_text(
367+
uploaded_pdf_for_watermark,
368+
watermark_text="InvalidNumericText",
369+
extra_body=extra_body,
370+
)
371+
372+
373+
def test_live_watermark_pdf_image_invalid_scale_bounds(
374+
pdfrest_api_key: str,
375+
pdfrest_live_base_url: str,
376+
uploaded_pdf_for_watermark: PdfRestFile,
377+
uploaded_watermark_pdf: PdfRestFile,
378+
) -> None:
379+
with (
380+
PdfRestClient(
381+
api_key=pdfrest_api_key,
382+
base_url=pdfrest_live_base_url,
383+
) as client,
384+
pytest.raises(PdfRestApiError, match=r"(?i)(watermark_file_scale|scale|range)"),
385+
):
386+
client.watermark_pdf_with_image(
387+
uploaded_pdf_for_watermark,
388+
watermark_file=uploaded_watermark_pdf,
389+
extra_body={"watermark_file_scale": "-0.01"},
390+
)
391+
392+
393+
@pytest.mark.parametrize(
394+
("extra_body", "error_match"),
395+
[
396+
pytest.param(
397+
{"opacity": "1.01"},
398+
r"(?i)(opacity|range)",
399+
id="opacity-above-max",
400+
),
401+
pytest.param(
402+
{"opacity": "-0.01"},
403+
r"(?i)(opacity|range)",
404+
id="opacity-below-min",
405+
),
406+
pytest.param(
407+
{"text_size": "101"},
408+
r"(?i)(text_size|size|range)",
409+
id="text-size-above-max",
410+
),
411+
pytest.param(
412+
{"text_size": "4"},
413+
r"(?i)(text_size|size|range)",
414+
id="text-size-below-min",
415+
),
416+
],
417+
)
418+
@pytest.mark.asyncio
419+
async def test_live_async_watermark_pdf_text_invalid_numeric_bounds(
420+
pdfrest_api_key: str,
421+
pdfrest_live_base_url: str,
422+
uploaded_pdf_for_watermark: PdfRestFile,
423+
extra_body: dict[str, str],
424+
error_match: str,
425+
) -> None:
426+
async with AsyncPdfRestClient(
427+
api_key=pdfrest_api_key,
428+
base_url=pdfrest_live_base_url,
429+
) as client:
430+
with pytest.raises(PdfRestApiError, match=error_match):
431+
await client.watermark_pdf_with_text(
432+
uploaded_pdf_for_watermark,
433+
watermark_text="AsyncInvalidNumericText",
434+
extra_body=extra_body,
435+
)
436+
437+
438+
@pytest.mark.asyncio
439+
async def test_live_async_watermark_pdf_image_invalid_scale_bounds(
440+
pdfrest_api_key: str,
441+
pdfrest_live_base_url: str,
442+
uploaded_pdf_for_watermark: PdfRestFile,
443+
uploaded_watermark_pdf: PdfRestFile,
444+
) -> None:
445+
async with AsyncPdfRestClient(
446+
api_key=pdfrest_api_key,
447+
base_url=pdfrest_live_base_url,
448+
) as client:
449+
with pytest.raises(
450+
PdfRestApiError,
451+
match=r"(?i)(watermark_file_scale|scale|range)",
452+
):
453+
await client.watermark_pdf_with_image(
454+
uploaded_pdf_for_watermark,
455+
watermark_file=uploaded_watermark_pdf,
456+
extra_body={"watermark_file_scale": "-0.01"},
457+
)

0 commit comments

Comments
 (0)