Skip to content

Commit ca9891d

Browse files
watermark-pdf: Remediate live testing gaps
Assisted-by: Codex
1 parent 7487414 commit ca9891d

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

tests/live/test_live_watermark_pdf.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,70 @@ def test_live_watermark_pdf_image_success(
101101
]
102102

103103

104+
@pytest.mark.parametrize(
105+
"horizontal_alignment",
106+
[
107+
pytest.param("left", id="left"),
108+
pytest.param("center", id="center"),
109+
pytest.param("right", id="right"),
110+
],
111+
)
112+
def test_live_watermark_pdf_text_horizontal_alignment_literals(
113+
pdfrest_api_key: str,
114+
pdfrest_live_base_url: str,
115+
uploaded_pdf_for_watermark: PdfRestFile,
116+
horizontal_alignment: str,
117+
) -> None:
118+
with PdfRestClient(
119+
api_key=pdfrest_api_key,
120+
base_url=pdfrest_live_base_url,
121+
) as client:
122+
response = client.watermark_pdf_with_text(
123+
uploaded_pdf_for_watermark,
124+
watermark_text="HORIZONTAL",
125+
horizontal_alignment=horizontal_alignment,
126+
output=f"align-h-{horizontal_alignment}",
127+
)
128+
129+
output_file = response.output_file
130+
assert output_file.name.startswith(f"align-h-{horizontal_alignment}")
131+
assert output_file.type == "application/pdf"
132+
assert output_file.size > 0
133+
assert str(response.input_id) == str(uploaded_pdf_for_watermark.id)
134+
135+
136+
@pytest.mark.parametrize(
137+
"vertical_alignment",
138+
[
139+
pytest.param("top", id="top"),
140+
pytest.param("center", id="center"),
141+
pytest.param("bottom", id="bottom"),
142+
],
143+
)
144+
def test_live_watermark_pdf_text_vertical_alignment_literals(
145+
pdfrest_api_key: str,
146+
pdfrest_live_base_url: str,
147+
uploaded_pdf_for_watermark: PdfRestFile,
148+
vertical_alignment: str,
149+
) -> None:
150+
with PdfRestClient(
151+
api_key=pdfrest_api_key,
152+
base_url=pdfrest_live_base_url,
153+
) as client:
154+
response = client.watermark_pdf_with_text(
155+
uploaded_pdf_for_watermark,
156+
watermark_text="VERTICAL",
157+
vertical_alignment=vertical_alignment,
158+
output=f"align-v-{vertical_alignment}",
159+
)
160+
161+
output_file = response.output_file
162+
assert output_file.name.startswith(f"align-v-{vertical_alignment}")
163+
assert output_file.type == "application/pdf"
164+
assert output_file.size > 0
165+
assert str(response.input_id) == str(uploaded_pdf_for_watermark.id)
166+
167+
104168
@pytest.mark.asyncio
105169
async def test_live_async_watermark_pdf_text_success(
106170
pdfrest_api_key: str,
@@ -128,6 +192,101 @@ async def test_live_async_watermark_pdf_text_success(
128192
assert str(response.input_id) == str(uploaded_pdf_for_watermark.id)
129193

130194

195+
@pytest.mark.parametrize(
196+
"horizontal_alignment",
197+
[
198+
pytest.param("left", id="left"),
199+
pytest.param("center", id="center"),
200+
pytest.param("right", id="right"),
201+
],
202+
)
203+
@pytest.mark.asyncio
204+
async def test_live_async_watermark_pdf_text_horizontal_alignment_literals(
205+
pdfrest_api_key: str,
206+
pdfrest_live_base_url: str,
207+
uploaded_pdf_for_watermark: PdfRestFile,
208+
horizontal_alignment: str,
209+
) -> None:
210+
async with AsyncPdfRestClient(
211+
api_key=pdfrest_api_key,
212+
base_url=pdfrest_live_base_url,
213+
) as client:
214+
response = await client.watermark_pdf_with_text(
215+
uploaded_pdf_for_watermark,
216+
watermark_text="ASYNC-HORIZONTAL",
217+
horizontal_alignment=horizontal_alignment,
218+
output=f"async-align-h-{horizontal_alignment}",
219+
)
220+
221+
output_file = response.output_file
222+
assert output_file.name.startswith(f"async-align-h-{horizontal_alignment}")
223+
assert output_file.type == "application/pdf"
224+
assert output_file.size > 0
225+
assert str(response.input_id) == str(uploaded_pdf_for_watermark.id)
226+
227+
228+
@pytest.mark.parametrize(
229+
"vertical_alignment",
230+
[
231+
pytest.param("top", id="top"),
232+
pytest.param("center", id="center"),
233+
pytest.param("bottom", id="bottom"),
234+
],
235+
)
236+
@pytest.mark.asyncio
237+
async def test_live_async_watermark_pdf_text_vertical_alignment_literals(
238+
pdfrest_api_key: str,
239+
pdfrest_live_base_url: str,
240+
uploaded_pdf_for_watermark: PdfRestFile,
241+
vertical_alignment: str,
242+
) -> None:
243+
async with AsyncPdfRestClient(
244+
api_key=pdfrest_api_key,
245+
base_url=pdfrest_live_base_url,
246+
) as client:
247+
response = await client.watermark_pdf_with_text(
248+
uploaded_pdf_for_watermark,
249+
watermark_text="ASYNC-VERTICAL",
250+
vertical_alignment=vertical_alignment,
251+
output=f"async-align-v-{vertical_alignment}",
252+
)
253+
254+
output_file = response.output_file
255+
assert output_file.name.startswith(f"async-align-v-{vertical_alignment}")
256+
assert output_file.type == "application/pdf"
257+
assert output_file.size > 0
258+
assert str(response.input_id) == str(uploaded_pdf_for_watermark.id)
259+
260+
261+
@pytest.mark.asyncio
262+
async def test_live_async_watermark_pdf_image_success(
263+
pdfrest_api_key: str,
264+
pdfrest_live_base_url: str,
265+
uploaded_pdf_for_watermark: PdfRestFile,
266+
uploaded_watermark_pdf: PdfRestFile,
267+
) -> None:
268+
async with AsyncPdfRestClient(
269+
api_key=pdfrest_api_key,
270+
base_url=pdfrest_live_base_url,
271+
) as client:
272+
response = await client.watermark_pdf_with_image(
273+
uploaded_pdf_for_watermark,
274+
watermark_file=uploaded_watermark_pdf,
275+
watermark_file_scale=0.75,
276+
behind_page=True,
277+
output="async-watermark-file",
278+
)
279+
280+
output_file = response.output_file
281+
assert output_file.type == "application/pdf"
282+
assert output_file.size > 0
283+
assert output_file.name.startswith("async-watermark-file")
284+
assert [str(value) for value in response.input_ids] == [
285+
str(uploaded_pdf_for_watermark.id),
286+
str(uploaded_watermark_pdf.id),
287+
]
288+
289+
131290
def test_live_watermark_pdf_invalid_alignment(
132291
pdfrest_api_key: str,
133292
pdfrest_live_base_url: str,

0 commit comments

Comments
 (0)