Skip to content

Commit 6b9ab60

Browse files
committed
fix: update fallback PNG to 50x50 image and fix import sorting
- Replaced 2x2 PNG fallback with 50x50 red PNG (132 bytes) that works with the API - Fixed import sorting issue in test_watermark_pdf_with_image_bytes - Applied consistent formatting - This ensures tests pass in CI where PIL/Pillow is not available The API rejects very small PNG images (1x1 or 2x2) with 500 errors.
1 parent 5c8a681 commit 6b9ab60

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

tests/integration/test_watermark_image_file_integration.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,24 @@ def create_test_image(tmp_path: Path, filename: str = "watermark.png") -> str:
3737
try:
3838
# Try to use PIL to create a proper image
3939
from PIL import Image
40-
img = Image.new('RGB', (100, 100), color='red')
40+
41+
img = Image.new("RGB", (100, 100), color="red")
4142
image_path = tmp_path / filename
4243
img.save(str(image_path))
4344
return str(image_path)
4445
except ImportError:
4546
# Fallback to a simple but valid PNG if PIL is not available
46-
# This is a 2x2 red PNG image
47+
# This is a 50x50 red PNG image
4748
png_data = (
48-
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x02\x00\x00\x00\x02'
49-
b'\x08\x02\x00\x00\x00\xfd\xd4\x9as\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf'
50-
b'\xc0\x00\x00\x03\x01\x01\x00\x18\xdd\x8d\xb4\x00\x00\x00\x00IEND\xaeB`\x82'
49+
b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
50+
b"\x00\x00\x00\x32\x00\x00\x00\x32\x08\x02\x00\x00\x00\x91\x5d\x1f"
51+
b"\xe6\x00\x00\x00\x4b\x49\x44\x41\x54\x78\x9c\xed\xce\xb1\x01\x00"
52+
b"\x10\x00\xc0\x30\xfc\xff\x33\x0f\x58\x32\x31\x34\x17\x64\xee\xf1"
53+
b"\xa3\xf5\x3a\x70\x57\x4b\xd4\x12\xb5\x44\x2d\x51\x4b\xd4\x12\xb5"
54+
b"\x44\x2d\x51\x4b\xd4\x12\xb5\x44\x2d\x51\x4b\xd4\x12\xb5\x44\x2d"
55+
b"\x51\x4b\xd4\x12\xb5\x44\x2d\x51\x4b\xd4\x12\xb5\x44\x2d\x71\x00"
56+
b"\x41\xaa\x01\x63\x85\xb8\x32\xab\x00\x00\x00\x00\x49\x45\x4e\x44"
57+
b"\xae\x42\x60\x82"
5158
)
5259
image_path = tmp_path / filename
5360
image_path.write_bytes(png_data)
@@ -92,18 +99,26 @@ def test_watermark_pdf_with_image_bytes(self, client, sample_pdf_path):
9299
"""Test watermark_pdf with image as bytes."""
93100
# Create a proper PNG image as bytes
94101
try:
95-
from PIL import Image
96102
import io
97-
img = Image.new('RGB', (100, 100), color='blue')
103+
104+
from PIL import Image
105+
106+
img = Image.new("RGB", (100, 100), color="blue")
98107
img_buffer = io.BytesIO()
99-
img.save(img_buffer, format='PNG')
108+
img.save(img_buffer, format="PNG")
100109
png_bytes = img_buffer.getvalue()
101110
except ImportError:
102-
# Fallback to a 2x2 blue PNG if PIL is not available
111+
# Fallback to a 50x50 red PNG if PIL is not available
103112
png_bytes = (
104-
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x02\x00\x00\x00\x02'
105-
b'\x08\x02\x00\x00\x00\xfd\xd4\x9as\x00\x00\x00\x0cIDATx\x9cc\x98\x00'
106-
b'\x00\x00\x05\x00\x01\x85\xb7\xb2\xf3\x00\x00\x00\x00IEND\xaeB`\x82'
113+
b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
114+
b"\x00\x00\x00\x32\x00\x00\x00\x32\x08\x02\x00\x00\x00\x91\x5d\x1f"
115+
b"\xe6\x00\x00\x00\x4b\x49\x44\x41\x54\x78\x9c\xed\xce\xb1\x01\x00"
116+
b"\x10\x00\xc0\x30\xfc\xff\x33\x0f\x58\x32\x31\x34\x17\x64\xee\xf1"
117+
b"\xa3\xf5\x3a\x70\x57\x4b\xd4\x12\xb5\x44\x2d\x51\x4b\xd4\x12\xb5"
118+
b"\x44\x2d\x51\x4b\xd4\x12\xb5\x44\x2d\x51\x4b\xd4\x12\xb5\x44\x2d"
119+
b"\x51\x4b\xd4\x12\xb5\x44\x2d\x51\x4b\xd4\x12\xb5\x44\x2d\x71\x00"
120+
b"\x41\xaa\x01\x63\x85\xb8\x32\xab\x00\x00\x00\x00\x49\x45\x4e\x44"
121+
b"\xae\x42\x60\x82"
107122
)
108123

109124
result = client.watermark_pdf(

0 commit comments

Comments
 (0)