Some checks failed
Run Tests / test (push) Failing after 1m51s
- Introduced a new table `application_setting` to store configurable application options. - Implemented functions to manage CSS color settings, including loading, updating, and reading environment overrides. - Added a new settings view to render and manage theme colors. - Updated UI to include a settings page with theme color management and environment overrides display. - Enhanced CSS styles for the settings page and sidebar navigation. - Created unit and end-to-end tests for the new settings functionality and CSS management.
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy.orm import Session
|
|
|
|
from services import settings as settings_service
|
|
|
|
|
|
@pytest.mark.usefixtures("db_session")
|
|
def test_read_css_settings_reflects_env_overrides(
|
|
api_client: TestClient, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
env_var = settings_service.css_key_to_env_var("--color-background")
|
|
monkeypatch.setenv(env_var, "#123456")
|
|
|
|
response = api_client.get("/api/settings/css")
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
|
|
assert body["variables"]["--color-background"] == "#123456"
|
|
assert body["env_overrides"]["--color-background"] == "#123456"
|
|
assert any(
|
|
source["env_var"] == env_var and source["value"] == "#123456"
|
|
for source in body["env_sources"]
|
|
)
|
|
|
|
|
|
@pytest.mark.usefixtures("db_session")
|
|
def test_update_css_settings_persists_changes(
|
|
api_client: TestClient, db_session: Session
|
|
) -> None:
|
|
payload = {"variables": {"--color-primary": "#112233"}}
|
|
|
|
response = api_client.put("/api/settings/css", json=payload)
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
|
|
assert body["variables"]["--color-primary"] == "#112233"
|
|
|
|
persisted = settings_service.get_css_color_settings(db_session)
|
|
assert persisted["--color-primary"] == "#112233"
|
|
|
|
|
|
@pytest.mark.usefixtures("db_session")
|
|
def test_update_css_settings_invalid_value_returns_422(
|
|
api_client: TestClient
|
|
) -> None:
|
|
response = api_client.put(
|
|
"/api/settings/css",
|
|
json={"variables": {"--color-primary": "not-a-color"}},
|
|
)
|
|
assert response.status_code == 422
|
|
body = response.json()
|
|
assert "color" in body["detail"].lower()
|