text2vector / tests /test_api.py
emilbm's picture
init project
5a5e912
raw
history blame contribute delete
907 Bytes
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