File size: 1,146 Bytes
b25b8f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_health_check():
    """Test the health endpoint."""
    response = client.get("/health")
    assert response.status_code == 200
    assert response.json() == {"status": "healthy", "service": "input-receiver"}

def test_receive_text():
    """Test the text ingestion endpoint."""
    response = client.post("/receive/text", json={"text": "2x + 4 = 10", "metadata": {"source": "test"}})
    assert response.status_code == 200
    assert response.json()["input_type"] == "text"
    assert response.json()["data"] == "2x + 4 = 10"

def test_receive_image():
    """Test the image ingestion endpoint with a dummy file."""
    # Create a dummy image file bytes
    dummy_image = b"fake_image_bytes"
    files = {"file": ("test.png", dummy_image, "image/png")}
    data = {"metadata": '{"source": "test"}'}
    
    response = client.post("/receive/image", files=files, data=data)
    assert response.status_code == 200
    assert response.json()["input_type"] == "image"
    assert response.json()["filename"] == "test.png"