File size: 785 Bytes
395651c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Unit tests for chat image validation (no Supabase / FastAPI app import)."""

import pytest
from fastapi import HTTPException

from app.chat_image_upload import validate_chat_image_bytes

_VALID_PNG = b"\x89PNG\r\n\x1a\n" + b"\x00" * 32


def test_validate_png_ok():
    ext, mime = validate_chat_image_bytes("a.png", _VALID_PNG, "image/png")
    assert ext == ".png"
    assert mime == "image/png"


def test_validate_rejects_bad_magic():
    with pytest.raises(HTTPException) as exc:
        validate_chat_image_bytes("a.png", b"xxxxxxxxxxxx", "image/png")
    assert exc.value.status_code == 400


def test_validate_rejects_empty():
    with pytest.raises(HTTPException) as exc:
        validate_chat_image_bytes("a.png", b"", "image/png")
    assert exc.value.status_code == 400