File size: 1,098 Bytes
78661be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Storage cards load a small thumbnail instead of the full corrected image."""
import numpy as np

from main import THUMB_MAX_SIDE, _thumb_url, _thumbnail


def test_thumb_url_sits_beside_the_corrected_image():
    url = "https://x.supabase.co/storage/v1/object/public/acra-images/jobs/abc/corrected.jpg"
    assert _thumb_url(url) == url.replace("/corrected.jpg", "/thumb.jpg")


def test_no_thumb_url_when_there_is_nothing_to_derive_it_from():
    # A missing or unexpected URL must give None, so the frontend uses the full
    # image instead of requesting an address that cannot exist.
    assert _thumb_url(None) is None
    assert _thumb_url("") is None
    assert _thumb_url("https://x/other.png") is None


def test_thumbnail_keeps_aspect_ratio_and_caps_the_long_side():
    img = np.zeros((1536, 1152, 3), dtype=np.uint8)
    h, w = _thumbnail(img).shape[:2]
    assert max(h, w) == THUMB_MAX_SIDE
    assert abs(w / h - 1152 / 1536) < 0.01


def test_small_images_are_never_enlarged():
    img = np.zeros((200, 300, 3), dtype=np.uint8)
    assert _thumbnail(img).shape[:2] == (200, 300)