-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_cli_config.py
More file actions
84 lines (72 loc) · 3.5 KB
/
test_cli_config.py
File metadata and controls
84 lines (72 loc) · 3.5 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
from socketsecurity.config import CliConfig
class TestCliConfig:
def test_api_token_from_env(self, monkeypatch):
monkeypatch.setenv("SOCKET_SECURITY_API_KEY", "test-token")
config = CliConfig.from_args([]) # Empty args list
assert config.api_token == "test-token"
def test_required_args(self):
"""Test that api token is required if not in environment"""
with pytest.raises(ValueError, match="API token is required"):
config = CliConfig.from_args([])
if not config.api_token:
raise ValueError("API token is required")
def test_default_values(self):
# Test that default values are set correctly
config = CliConfig.from_args(["--api-token", "test"])
assert config.branch == ""
assert config.target_path == "./"
assert config.files == "[]"
@pytest.mark.parametrize("flag,attr", [
("--enable-debug", "enable_debug"),
("--disable-blocking", "disable_blocking"),
("--allow-unverified", "allow_unverified"),
("--enable-diff", "enable_diff")
])
def test_boolean_flags(self, flag, attr):
config = CliConfig.from_args(["--api-token", "test", flag])
assert getattr(config, attr) is True
def test_enable_diff_default_false(self):
"""Test that enable_diff defaults to False"""
config = CliConfig.from_args(["--api-token", "test"])
assert config.enable_diff is False
def test_enable_diff_with_integration_api(self):
"""Test that enable_diff can be used with integration api"""
config = CliConfig.from_args(["--api-token", "test", "--integration", "api", "--enable-diff"])
assert config.enable_diff is True
assert config.integration_type == "api"
def test_strict_blocking_flag(self):
"""Test that --strict-blocking flag is parsed correctly"""
config = CliConfig.from_args(["--api-token", "test", "--strict-blocking"])
assert config.strict_blocking is True
def test_strict_blocking_default_false(self):
"""Test that strict_blocking defaults to False"""
config = CliConfig.from_args(["--api-token", "test"])
assert config.strict_blocking is False
def test_strict_blocking_with_disable_blocking(self):
"""Test that both flags can be set (disable-blocking should win)"""
config = CliConfig.from_args([
"--api-token", "test",
"--strict-blocking",
"--disable-blocking"
])
assert config.strict_blocking is True
assert config.disable_blocking is True
def test_workspace_flag(self):
"""Test that --workspace is parsed and stored correctly."""
config = CliConfig.from_args(["--api-token", "test", "--workspace", "my-workspace"])
assert config.workspace == "my-workspace"
def test_workspace_default_is_none(self):
"""Test that workspace defaults to None when not supplied."""
config = CliConfig.from_args(["--api-token", "test"])
assert config.workspace is None
def test_workspace_is_independent_of_workspace_name(self):
"""--workspace and --workspace-name are distinct flags with distinct purposes."""
config = CliConfig.from_args([
"--api-token", "test",
"--workspace", "my-workspace",
"--sub-path", ".",
"--workspace-name", "monorepo-suffix",
])
assert config.workspace == "my-workspace"
assert config.workspace_name == "monorepo-suffix"