Spaces:
Sleeping
Sleeping
| from typing import Dict | |
| from fastapi.testclient import TestClient | |
| def register_user(client: TestClient, payload: Dict[str, str]): | |
| response = client.post("/api/auth/signup", json=payload) | |
| assert response.status_code == 200 | |
| return response.json() | |
| def login_user(client: TestClient, payload: Dict[str, str]): | |
| response = client.post("/api/auth/login", json=payload) | |
| assert response.status_code == 200 | |
| return response.json() | |
| def test_signup_and_me_endpoint(client: TestClient): | |
| payload = { | |
| "email": "user@example.com", | |
| "password": "securepass", | |
| "display_name": "Marine User", | |
| "organization": "Ocean Org", | |
| "role": "citizen", | |
| } | |
| signup_response = register_user(client, payload) | |
| token = signup_response["access_token"] | |
| me_response = client.get( | |
| "/api/auth/me", | |
| headers={"Authorization": f"Bearer {token}"}, | |
| ) | |
| assert me_response.status_code == 200 | |
| me_data = me_response.json() | |
| assert me_data["email"] == payload["email"] | |
| assert me_data["display_name"] == payload["display_name"] | |
| def test_login_returns_new_token(client: TestClient): | |
| credentials = { | |
| "email": "login@example.com", | |
| "password": "strongpassword", | |
| "display_name": "Login User", | |
| "organization": "Ocean Org", | |
| "role": "citizen", | |
| } | |
| register_user(client, credentials) | |
| login_response = login_user(client, credentials) | |
| assert login_response["access_token"] | |
| assert login_response["user"]["email"] == credentials["email"] | |
| def test_incident_classification_flow(client: TestClient): | |
| credentials = { | |
| "email": "incident@example.com", | |
| "password": "password123", | |
| "display_name": "Reporter", | |
| "organization": "Ocean Org", | |
| "role": "citizen", | |
| } | |
| signup_response = register_user(client, credentials) | |
| token = signup_response["access_token"] | |
| response = client.post( | |
| "/api/incidents/classify", | |
| data={ | |
| "description": "A major oil spill observed near the coast", | |
| "latitude": "12.34", | |
| "longitude": "56.78", | |
| }, | |
| files={ | |
| "image": ("evidence.jpg", b"fake-image-bytes", "image/jpeg"), | |
| }, | |
| headers={"Authorization": f"Bearer {token}"}, | |
| ) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["incident_class"] == "Incident" | |
| assert data["severity"] == "high" | |
| assert "incident_id" in data | |