Модуль settings: значения по умолчанию, версия настроек, защищённые ключи, перенос проектных настроек из config.example.json (учётные данные остаются у агента). Фикстура tests/fixtures/config.example.json — копия admin/jira-sync/config.example.json. .pytest_cache/ добавлен в .gitignore. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014Typ5sXWNMFirr2va2uL8o
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
import json
|
||
from pathlib import Path
|
||
|
||
import pytest
|
||
|
||
from jira_hub import db, settings
|
||
|
||
FIXTURE = Path(__file__).parent / "fixtures" / "config.example.json"
|
||
|
||
|
||
def fresh():
|
||
conn = db.connect(":memory:")
|
||
settings.ensure_defaults(conn)
|
||
return conn
|
||
|
||
|
||
def test_defaults_and_tokens():
|
||
conn = fresh()
|
||
assert settings.get(conn, "base_jql") == "project = AURORA AND labels = AWPCA"
|
||
assert settings.get(conn, "pacing")["ensure_fields"] == 120
|
||
tok = settings.tokens(conn)
|
||
assert len(tok["agent"]) > 20 and tok["agent"] != tok["client"]
|
||
assert "tokens" not in settings.get_all(conn)
|
||
|
||
|
||
def test_set_bumps_version():
|
||
conn = fresh()
|
||
v0 = settings.get(conn, "settings_version")
|
||
v1 = settings.set_(conn, "pacing", {"ensure_fields": 5})
|
||
assert v1 == v0 + 1
|
||
assert settings.get(conn, "pacing") == {"ensure_fields": 5}
|
||
|
||
|
||
@pytest.mark.parametrize("key", ["tokens", "settings_version", "schema_version"])
|
||
def test_protected_keys(key):
|
||
conn = fresh()
|
||
with pytest.raises(ValueError):
|
||
settings.set_(conn, key, "x")
|
||
|
||
|
||
def test_init_from_config():
|
||
conn = fresh()
|
||
cfg = json.loads(FIXTURE.read_text(encoding="utf-8"))
|
||
keys = settings.init_from_config(conn, cfg)
|
||
assert "transitions_map" in keys
|
||
assert settings.get(conn, "field_ids")["planned_end"] == "customfield_10802"
|
||
assert settings.get(conn, "issue_types")["epic"] == {"name": "Фича", "id": "12300"}
|
||
assert settings.get(conn, "board_id") == 4216
|
||
assert settings.get(conn, "pacing") == settings.DEFAULT_PACING
|
||
agent_view = settings.for_agent(conn)
|
||
assert "tokens" not in agent_view and "auth" not in agent_view and "base_url" not in agent_view
|
||
assert agent_view["link_types"]["связанные"] == "ASUPR_Связанные"
|
||
with pytest.raises(RuntimeError):
|
||
settings.init_from_config(conn, cfg)
|
||
settings.init_from_config(conn, cfg, force=True)
|