IDKHowToCodeFr/tinyml-backend
1
1import pytest2from fastapi.testclient import TestClient3import sys4import os5 6# Ensure backend is in path7sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../backend')))8from main import app9 10client = TestClient(app)11 12def test_health_check():13 """Test that the backend API is up and running."""14 # Assuming there varies a root or health endpoint. If not, this is a placeholder.15 response = client.get("/")16 # Even if it's 404 because no root exists, the server responds.17 assert response.status_code in [200, 404]18 19def test_predict_endpoint_validation():20 """Test that the predict endpoint rejects invalid data."""21 payload = {22 "Heart_Rate": "invalid_string",23 "SpO2_Level": 9824 }25 response = client.post("/predict", json=payload)26 assert response.status_code == 422 # Unprocessable Entity (Pydantic validation)27 28 