Backend API: auth, projects/images/annotations, R2 presign, tracing, thumbnails, pagination, tests, docs
This commit is contained in:
parent
5c5deed2f5
commit
f8ed08b854
49 changed files with 2626 additions and 0 deletions
30
tests/test_thumbnails.py
Normal file
30
tests/test_thumbnails.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
"""Thumbnail resize: pure bytes in/out, no R2, no DB."""
|
||||
from io import BytesIO
|
||||
|
||||
from PIL import Image as PILImage
|
||||
|
||||
from shared.thumbnails import resize_to_thumbnail
|
||||
|
||||
|
||||
def _jpeg(width: int, height: int) -> bytes:
|
||||
buf = BytesIO()
|
||||
PILImage.new("RGB", (width, height), (200, 30, 30)).save(buf, "JPEG", quality=90)
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
def test_resize_bounds_long_side():
|
||||
out = resize_to_thumbnail(_jpeg(2000, 1000))
|
||||
with PILImage.open(BytesIO(out)) as im:
|
||||
assert max(im.size) <= 512
|
||||
assert im.format == "JPEG"
|
||||
|
||||
|
||||
def test_resize_small_image_not_upscaled():
|
||||
out = resize_to_thumbnail(_jpeg(100, 60))
|
||||
with PILImage.open(BytesIO(out)) as im:
|
||||
assert im.size == (100, 60)
|
||||
|
||||
|
||||
def test_resize_output_is_smaller():
|
||||
big = _jpeg(1920, 1080)
|
||||
assert len(resize_to_thumbnail(big)) < len(big)
|
||||
Loading…
Add table
Add a link
Reference in a new issue