| Server IP : 3.147.158.171 / Your IP : 216.73.216.88 Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.21 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /tsai/repo/api/tests/unit/ |
Upload File : |
"""Tests for get_default_image_format() — the IMAGE_STORAGE_FORMAT env var helper.
The contract: only 'png' and 'jpeg' are honoured, matching is case-insensitive,
and anything else (including an unset var) falls back to 'png'. Callers in
gpt_image_2, image_v2, and wp all rely on the fallback never returning an
unsupported format.
"""
from unittest.mock import patch
from app.services.image import get_default_image_format
class TestGetDefaultImageFormat:
@patch.dict("os.environ", {"IMAGE_STORAGE_FORMAT": "jpeg"})
def test_returns_jpeg_when_set(self):
assert get_default_image_format() == "jpeg"
@patch.dict("os.environ", {"IMAGE_STORAGE_FORMAT": "png"})
def test_returns_png_when_set(self):
assert get_default_image_format() == "png"
@patch.dict("os.environ", {"IMAGE_STORAGE_FORMAT": "JPEG"})
def test_case_insensitive(self):
assert get_default_image_format() == "jpeg"
@patch.dict("os.environ", {"IMAGE_STORAGE_FORMAT": "bmp"})
def test_invalid_value_falls_back_to_png(self):
assert get_default_image_format() == "png"
@patch.dict("os.environ", {}, clear=True)
def test_unset_falls_back_to_png(self):
assert get_default_image_format() == "png"