GRM-54: Integrate tea Gitea CLI for API interactions (#68)

This commit is contained in:
2026-06-22 07:04:58 +00:00
parent b8ab4f854b
commit 28e61aa166
17 changed files with 1319 additions and 265 deletions
+53 -2
View File
@@ -80,6 +80,56 @@ class TestVerify:
setup._verify(".venv/bin")
class TestConfigureTeaLogin:
def test_tea_not_installed(self) -> None:
with patch("shutil.which", return_value=None):
with patch.dict("os.environ", {"REPO_TOKEN": "tok"}, clear=True):
setup._configure_tea_login()
def test_no_repo_token(self) -> None:
with patch("shutil.which", return_value="/usr/bin/tea"):
with patch.dict("os.environ", {}, clear=True):
setup._configure_tea_login()
def test_login_already_exists(self) -> None:
import subprocess
mock_result = subprocess.CompletedProcess(
args=["tea", "login", "list"], returncode=0, stdout="grm https://git.example.com", stderr=""
)
with patch("shutil.which", return_value="/usr/bin/tea"):
with patch.dict("os.environ", {"REPO_TOKEN": "tok"}, clear=True):
with patch("subprocess.run", return_value=mock_result):
setup._configure_tea_login()
def test_login_added_successfully(self) -> None:
import subprocess
list_result = subprocess.CompletedProcess(args=["tea", "login", "list"], returncode=0, stdout="", stderr="")
add_result = subprocess.CompletedProcess(
args=["tea", "login", "add"], returncode=0, stdout="Login added", stderr=""
)
default_result = subprocess.CompletedProcess(
args=["tea", "login", "default"], returncode=0, stdout="", stderr=""
)
with patch("shutil.which", return_value="/usr/bin/tea"):
with patch.dict("os.environ", {"REPO_TOKEN": "tok"}, clear=True):
with patch("subprocess.run", side_effect=[list_result, add_result, default_result]):
setup._configure_tea_login()
def test_login_add_failure(self) -> None:
import subprocess
list_result = subprocess.CompletedProcess(args=["tea", "login", "list"], returncode=0, stdout="", stderr="")
add_result = subprocess.CompletedProcess(
args=["tea", "login", "add"], returncode=1, stdout="", stderr="auth failed"
)
with patch("shutil.which", return_value="/usr/bin/tea"):
with patch.dict("os.environ", {"REPO_TOKEN": "tok"}, clear=True):
with patch("subprocess.run", side_effect=[list_result, add_result]):
setup._configure_tea_login()
class TestMain:
def test_bin_not_found(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(tmp_path)
@@ -101,7 +151,8 @@ class TestMain:
with patch("scripts.setup._install_python_deps"):
with patch("scripts.setup._install_ansible_collections"):
with patch("scripts.setup._install_pre_commit_hooks"):
with patch("scripts.setup._verify"):
result = runner.invoke(setup.main, ["--bin", str(bin_dir)])
with patch("scripts.setup._configure_tea_login"):
with patch("scripts.setup._verify"):
result = runner.invoke(setup.main, ["--bin", str(bin_dir)])
assert result.exit_code == 0
assert "Setup complete" in result.output