| import requests | |
| def test_health_endpoint(): | |
| """Test the health endpoint of the API.""" | |
| base_url = "http://localhost:8000" | |
| health_url = f"{base_url}/health" | |
| try: | |
| response = requests.get(health_url, timeout=10) | |
| response.raise_for_status() | |
| data = response.json() | |
| assert response.status_code == 200, "Health endpoint did not return status 200" | |
| assert data["status"] == "healthy", "Service is not healthy" | |
| assert "model" in data, "Model information missing in health response" | |
| assert "version" in data, "Version information missing in health response" | |
| print("β Health endpoint test passed.") | |
| except Exception as e: | |
| print(f"β Health endpoint test failed: {e}") | |
| def test_api_response(): | |
| """Test the new API response endpoint.""" | |
| base_url = "http://localhost:8000" | |
| response_url = f"{base_url}/api/response" | |
| try: | |
| payload = {"message": "Hello, API!"} | |
| response = requests.post(response_url, json=payload, timeout=10) | |
| response.raise_for_status() | |
| data = response.json() | |
| assert response.status_code == 200, "API response endpoint did not return status 200" | |
| assert data["status"] == "success", "API response status is not success" | |
| assert data["received_message"] == "Hello, API!", "Received message mismatch" | |
| assert "response_message" in data, "Response message missing in API response" | |
| print("β API response endpoint test passed.") | |
| except Exception as e: | |
| print(f"β API response endpoint test failed: {e}") | |
| if __name__ == "__main__": | |
| test_health_endpoint() | |
| test_api_response() | |