import json from pathlib import Path from jira_hub import cli, db, paths, settings FIXTURE = Path(__file__).parent / "fixtures" / "config.example.json" def test_init_import_tokens(tmp_path, monkeypatch, capsys): monkeypatch.setenv("JIRA_HUB_HOME", str(tmp_path / "home")) assert cli.main(["init", "--config", str(FIXTURE)]) == 0 out = capsys.readouterr().out assert "transitions_map" in out and "агентский токен" in out assert cli.main(["init", "--config", str(FIXTURE)]) == 1 assert "уже инициализирован" in capsys.readouterr().err conn = db.connect(paths.db_path()) assert settings.get(conn, "board_id") == 4216 (tmp_path / "pkg").mkdir() (tmp_path / "pkg" / "tasks.csv").write_text("Код,Статус по факту,Вид работы\nAURORA-1,В работе,UI\n", encoding="utf-8") assert cli.main(["import", str(tmp_path / "pkg")]) == 0 rep = json.loads(capsys.readouterr().out) assert rep["notes"] == 1 and rep["missing_keys"] == ["AURORA-1"] assert cli.main(["tokens"]) == 0 assert settings.tokens(conn)["client"] in capsys.readouterr().out conn.close()