-
Notifications
You must be signed in to change notification settings - Fork 8k
Expand file tree
/
Copy pathtest_approval_command.py
More file actions
59 lines (47 loc) · 1.99 KB
/
test_approval_command.py
File metadata and controls
59 lines (47 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Tests for approval CLI command"""
import pytest
from typer.testing import CliRunner
from unittest.mock import patch, MagicMock
from specify_cli.approval_command import approval_command
import typer
def test_approval_status_no_config():
"""Test approval status when no config exists"""
with patch("specify_cli.approval_command.ApprovalGatesConfig.load", return_value=None):
# Create a simple typer app to test the command
app = typer.Typer()
app.command()(approval_command)
runner = CliRunner()
result = runner.invoke(app, ["--action", "status"])
assert result.exit_code == 0
assert "No approval gates configured" in result.stdout
def test_approval_status_with_config():
"""Test approval status with gates configured"""
# Mock configuration
mock_config = MagicMock()
mock_config.gates = {
"specify": {"enabled": True, "min_approvals": 1},
"plan": {"enabled": True, "min_approvals": 2},
}
with patch("specify_cli.approval_command.ApprovalGatesConfig.load", return_value=mock_config):
app = typer.Typer()
app.command()(approval_command)
runner = CliRunner()
result = runner.invoke(app, ["--action", "status"])
assert result.exit_code == 0
assert "Approval gates enabled" in result.stdout
assert "specify" in result.stdout
assert "plan" in result.stdout
def test_approval_default_action():
"""Test approval command with default action (status)"""
mock_config = MagicMock()
mock_config.gates = {
"specify": {"enabled": True, "min_approvals": 1},
}
with patch("specify_cli.approval_command.ApprovalGatesConfig.load", return_value=mock_config):
app = typer.Typer()
app.command()(approval_command)
runner = CliRunner()
# Invoke without --action (should default to status)
result = runner.invoke(app, [])
assert result.exit_code == 0
assert "Approval gates enabled" in result.stdout