Spaces:
Sleeping
Sleeping
| from unittest.mock import patch, AsyncMock | |
| from fastapi.testclient import TestClient | |
| # Mock database connections before importing app | |
| with patch("app.main.connect_to_mongo", new_callable=AsyncMock), \ | |
| patch("app.main.connect_to_database", new_callable=AsyncMock): | |
| from app.main import app | |
| client = TestClient(app) | |
| def test_404_error_handling(): | |
| response = client.get("/non-existent-route") | |
| assert response.status_code == 404 | |
| data = response.json() | |
| assert data["success"] is False | |
| assert data["error"] == "Not Found" | |
| assert data["detail"] == "Resource not found" | |
| assert "request_id" in data | |
| assert "timestamp" in data | |
| def test_validation_error_handling(): | |
| # token query param is required for this endpoint | |
| response = client.post("/debug/verify-token") | |
| assert response.status_code == 422 | |
| data = response.json() | |
| assert data["success"] is False | |
| assert data["error"] == "Validation Error" | |
| assert data["detail"] == "The request contains invalid data" | |
| assert "errors" in data | |
| assert isinstance(data["errors"], list) | |
| assert len(data["errors"]) > 0 | |
| assert "field" in data["errors"][0] | |
| assert "message" in data["errors"][0] | |
| assert "type" in data["errors"][0] | |