Spaces:
Runtime error
Runtime error
File size: 1,008 Bytes
8ee0848 | 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 31 | # tests/test_api.py
import pytest
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_health_check():
"""Vérifie que /health répond bien avec status ok"""
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
def test_predict_positive():
"""Vérifie qu'une phrase positive est détectée correctement"""
response = client.post("/predict", json={"text": "I love this product, it's amazing!"})
assert response.status_code == 200
result = response.json()
assert "sentiment" in result
assert result["sentiment"] == "positive"
def test_predict_negative():
"""Vérifie qu'une phrase négative est détectée correctement"""
response = client.post("/predict", json={"text": "I hate this, it is terrible."})
assert response.status_code == 200
result = response.json()
assert "sentiment" in result
assert result["sentiment"] == "negative"
|