Files
calminer/tests/unit/test_settings_routes.py
zwitschi 97b1c0360b
Some checks failed
Run Tests / e2e tests (push) Failing after 1m27s
Run Tests / lint tests (push) Failing after 6s
Run Tests / unit tests (push) Failing after 7s
Refactor test cases for improved readability and consistency
- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation.
- Adjusted assertions to use multi-line formatting for better readability.
- Added new test cases for theme settings API to ensure proper functionality.
- Ensured consistent use of line breaks and spacing across test files for uniformity.
2025-10-27 10:32:55 +01:00

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()