-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_config_cmd.py
More file actions
98 lines (75 loc) · 3.91 KB
/
test_config_cmd.py
File metadata and controls
98 lines (75 loc) · 3.91 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import json
from typer.testing import CliRunner
from pumpfun_cli.cli import app
runner = CliRunner()
def test_config_set_and_get(tmp_path, monkeypatch):
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
result = runner.invoke(app, ["config", "set", "rpc", "https://example.com"])
assert result.exit_code == 0
result = runner.invoke(app, ["config", "get", "rpc"])
assert result.exit_code == 0
assert "https://example.com" in result.output
def test_config_list(tmp_path, monkeypatch):
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
runner.invoke(app, ["config", "set", "rpc", "https://example.com"])
result = runner.invoke(app, ["config", "list"])
assert result.exit_code == 0
assert "rpc" in result.output
def test_config_list_json(tmp_path, monkeypatch):
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
runner.invoke(app, ["config", "set", "rpc", "https://example.com"])
result = runner.invoke(app, ["--json", "config", "list"])
assert result.exit_code == 0
data = json.loads(result.output)
assert data["rpc"] == "https://example.com"
def test_config_set_json_output(tmp_path, monkeypatch):
"""config set outputs JSON with --json flag (leading)."""
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
result = runner.invoke(app, ["--json", "config", "set", "rpc", "https://example.com"])
assert result.exit_code == 0
data = json.loads(result.output)
assert data == {"key": "rpc", "value": "https://example.com", "status": "saved"}
def test_config_set_json_trailing(tmp_path, monkeypatch):
"""config set outputs JSON with --json flag (trailing)."""
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
result = runner.invoke(app, ["config", "set", "rpc", "https://example.com", "--json"])
assert result.exit_code == 0
data = json.loads(result.output)
assert data == {"key": "rpc", "value": "https://example.com", "status": "saved"}
def test_config_get_json_output(tmp_path, monkeypatch):
"""config get outputs JSON with --json flag."""
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
runner.invoke(app, ["config", "set", "rpc", "https://example.com"])
result = runner.invoke(app, ["--json", "config", "get", "rpc"])
assert result.exit_code == 0
data = json.loads(result.output)
assert data == {"key": "rpc", "value": "https://example.com"}
def test_config_delete_json_output(tmp_path, monkeypatch):
"""config delete outputs JSON with --json flag."""
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
runner.invoke(app, ["config", "set", "rpc", "https://example.com"])
result = runner.invoke(app, ["--json", "config", "delete", "rpc"])
assert result.exit_code == 0
data = json.loads(result.output)
assert data == {"key": "rpc", "status": "deleted"}
def test_config_get_json_trailing(tmp_path, monkeypatch):
"""config get outputs JSON with --json flag (trailing)."""
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
runner.invoke(app, ["config", "set", "rpc", "https://example.com"])
result = runner.invoke(app, ["config", "get", "rpc", "--json"])
assert result.exit_code == 0
data = json.loads(result.output)
assert data == {"key": "rpc", "value": "https://example.com"}
def test_config_set_unknown_key(tmp_path, monkeypatch):
"""config set rejects unknown config keys and does not persist them."""
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
result = runner.invoke(app, ["config", "set", "rpcc", "https://example.com"])
assert result.exit_code != 0
assert "unknown config key" in result.output.lower()
assert "valid keys" in result.output.lower()
# Assert the invalid key was not persisted
list_result = runner.invoke(app, ["--json", "config", "list"])
assert list_result.exit_code == 0
import json
data = json.loads(list_result.output) if list_result.output.strip() else {}
assert "rpcc" not in data