from fastapi.testclient import TestClient from app.main import app client = TestClient(app) def test_healthcheck() -> None: response = client.get("/health") assert response.status_code == 200 assert response.json() == {"status": "ok"} def test_openapi_contains_expected_paths() -> None: response = client.get("/openapi.json") assert response.status_code == 200 paths = response.json()["paths"] assert "/api/v1/terrain/profile" in paths assert "/api/v1/terrain/los" in paths assert "/api/v1/link/budget" in paths assert "/api/v1/coverage" in paths def test_profile_endpoint_returns_geodesic_samples() -> None: response = client.post( "/api/v1/terrain/profile", json={ "start": {"lat": 60.17, "lon": 24.94}, "end": {"lat": 60.25, "lon": 25.10}, "samples": 4, "include_buildings": True, "include_canopy": True, "k_factor": 1.333, }, ) assert response.status_code == 200 data = response.json() assert data["distance_m"] > 0 assert len(data["samples"]) == 4 assert data["path_geojson"]["type"] == "LineString" def test_elevation_returns_not_implemented_without_dem() -> None: response = client.get("/api/v1/terrain/elevation", params={"lat": 60.17, "lon": 24.94}) assert response.status_code == 501 def test_los_endpoint_returns_obstruction_summary_fields() -> None: response = client.post( "/api/v1/terrain/los", json={ "tx": {"lat": 59.935, "lon": 30.305, "height_agl": 30}, "rx": {"lat": 59.945, "lon": 30.325, "height_agl": 2}, "frequency_mhz": 433, "fresnel_clearance": 0.6, "include_buildings": False, "include_canopy": False, "k_factor": 1.333, "samples": 16, }, ) assert response.status_code == 200 data = response.json() assert "obstructions" in data assert "geometric_obstructions" in data assert data["fresnel_violations_count"] == len(data["obstructions"]) assert data["geometric_obstructions_count"] == len(data["geometric_obstructions"]) assert data["building_obstructions_count"] == len( [item for item in data["geometric_obstructions"] if item["type"] == "building"] ) def test_manual_link_budget_endpoint() -> None: response = client.post( "/api/v1/link/budget", json={ "tx": {"lat": 60.17, "lon": 24.94, "height_agl": 30, "power_dbm": 37, "gain_dbi": 8}, "rx": { "lat": 60.25, "lon": 25.10, "height_agl": 2, "gain_dbi": 2, "sensitivity_dbm": -110, }, "frequency_mhz": 433, "model": "manual", "include_buildings": True, "include_vegetation": True, "k_factor": 1.333, }, ) assert response.status_code == 200 data = response.json() assert data["fspl_db"] > 0 assert data["link_viable"] is True