Fix watchdog gaps, image failures and stale reminders
- catch httpx errors on send/heartbeat so a dead signal-api alerts instead of failing silently - never let compose/images block the text post; count failed attempts - drop reminders for events removed from the feed, using the feed's coverage horizon so the 30-event cap does not mark future events gone - persist feed validators only after a successful parse - do not seed from an empty feed - flatten transparent images onto white; catch decompression bombs - --dump uses a throwaway database - avoid duplicated postcode in the venue line - remove dead code; add regression tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
|
||||
import httpx
|
||||
from PIL import Image
|
||||
|
||||
from calbot.config import ImagesConfig
|
||||
from calbot.images import ImageService
|
||||
|
||||
|
||||
def make_service(tmp_path, **overrides) -> ImageService:
|
||||
return ImageService(ImagesConfig(**overrides), tmp_path, httpx.Client())
|
||||
|
||||
|
||||
def test_transparent_png_is_flattened_onto_white(tmp_path):
|
||||
buffer = io.BytesIO()
|
||||
Image.new("RGBA", (120, 120), (255, 0, 0, 0)).save(buffer, "PNG")
|
||||
|
||||
service = make_service(tmp_path)
|
||||
result = service._resize(buffer.getvalue())
|
||||
assert result
|
||||
|
||||
image = Image.open(io.BytesIO(result))
|
||||
assert image.mode == "RGB"
|
||||
red, green, blue = image.getpixel((60, 60))
|
||||
assert min(red, green, blue) > 240
|
||||
|
||||
|
||||
def test_oversized_image_is_downscaled(tmp_path):
|
||||
buffer = io.BytesIO()
|
||||
Image.new("RGB", (4000, 3000), (10, 80, 200)).save(buffer, "PNG")
|
||||
service = make_service(tmp_path, max_pixels=400, max_bytes=50_000)
|
||||
result = service._resize(buffer.getvalue())
|
||||
assert result
|
||||
assert len(result) <= 50_000
|
||||
image = Image.open(io.BytesIO(result))
|
||||
assert max(image.size) <= 400
|
||||
|
||||
|
||||
def test_decompression_bomb_does_not_propagate(tmp_path):
|
||||
service = make_service(tmp_path)
|
||||
|
||||
def boom(url):
|
||||
raise Image.DecompressionBombError("too many pixels")
|
||||
|
||||
service._cached_or_download = boom # type: ignore[method-assign]
|
||||
assert service.data_uri("https://example.test/huge.jpg") is None
|
||||
Reference in New Issue
Block a user