File size: 907 Bytes
5a5e912
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi.testclient import TestClient
from app.main import app

client = TestClient(app)


def test_embed() -> None:
    """Test the /embed endpoint with valid input."""
    response = client.post("/embed", json={"texts": ["query: Hello world"]})
    assert response.status_code == 200  # OK
    data = response.json()
    assert "embeddings" in data
    assert len(data["embeddings"][0]) == 1024


def test_embed_no_texts() -> None:
    """Test the /embed endpoint with no texts provided."""
    response = client.post("/embed", json={})
    assert response.status_code == 422  # Unprocessable Entity


def test_embed_long_text() -> None:
    """Test the /embed endpoint with a text longer than 2000 characters."""
    long_text = "query: " + "a" * 1994  # 2001 characters
    response = client.post("/embed", json={"texts": [long_text]})
    assert response.status_code == 422  # Unprocessable Entity