feat: config files, settings screen, hardware check
- Add config.py with multi-source config (YAML, .env, env vars) - Add .env.example and config.yaml.example - Add settings API endpoints (GET/POST /api/v1/settings) - Add status endpoint (GET /api/v1/status) with hardware subsystem check - Add settings screen to web client (protected by API token) - Add localization strings for settings UI - Add tests for config module and new endpoints - Update README with config documentation
This commit is contained in:
@@ -92,3 +92,58 @@ class TestNotifyEndpoint:
|
||||
assert response.status_code == 401
|
||||
|
||||
del os.environ["API_TOKEN"]
|
||||
|
||||
|
||||
class TestSettingsEndpoint:
|
||||
def test_get_settings_without_token_returns_401(self, client: TestClient) -> None:
|
||||
response = client.get("/api/v1/settings")
|
||||
assert response.status_code == 401
|
||||
|
||||
def test_get_settings_with_valid_token(self, client: TestClient) -> None:
|
||||
os.environ["API_TOKEN"] = "settings-token"
|
||||
|
||||
response = client.get(
|
||||
"/api/v1/settings",
|
||||
headers={"Authorization": "Bearer settings-token"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "dashboard_pin" in data
|
||||
assert "api_token" in data
|
||||
assert "host" in data
|
||||
assert "port" in data
|
||||
|
||||
del os.environ["API_TOKEN"]
|
||||
|
||||
def test_update_settings(self, client: TestClient) -> None:
|
||||
os.environ["API_TOKEN"] = "update-token"
|
||||
|
||||
response = client.post(
|
||||
"/api/v1/settings",
|
||||
json={
|
||||
"dashboard_pin": "9999",
|
||||
"api_token": "new-token",
|
||||
},
|
||||
headers={"Authorization": "Bearer update-token"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["dashboard_pin"] == "9999"
|
||||
assert data["api_token"] == "new-token"
|
||||
|
||||
del os.environ["API_TOKEN"]
|
||||
|
||||
|
||||
class TestStatusEndpoint:
|
||||
def test_status_returns_subsystems(self, client: TestClient) -> None:
|
||||
# Ensure subsystems are initialized
|
||||
if not hasattr(app.state, "subsystems"):
|
||||
app.state.subsystems = {}
|
||||
|
||||
response = client.get("/api/v1/status")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "subsystems" in data
|
||||
assert "config" in data
|
||||
assert "pin_configured" in data["config"]
|
||||
assert "token_configured" in data["config"]
|
||||
|
||||
Reference in New Issue
Block a user