Skip to content

Commit c7f8108

Browse files
committed
Add test cases
1 parent 4472c22 commit c7f8108

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"data": {
3+
"AccountProfile": {
4+
"id": "1816ebcd-cea7-3bf7-3fc9-c51282f03fe7",
5+
"display_label": "Admin",
6+
"account_type": {
7+
"value": "User",
8+
"__typename": "TextAttribute",
9+
"updated_at": "2025-01-02T16:06:15.565985+00:00"
10+
},
11+
"status": {
12+
"label": "Active",
13+
"value": "active",
14+
"updated_at": "2025-01-02T16:06:15.565985+00:00",
15+
"__typename": "Dropdown"
16+
},
17+
"description": {
18+
"value": null,
19+
"updated_at": "2025-01-02T16:06:15.565985+00:00",
20+
"__typename": "TextAttribute"
21+
},
22+
"label": {
23+
"value": "Admin",
24+
"updated_at": "2025-01-02T16:06:15.565985+00:00",
25+
"__typename": "TextAttribute"
26+
},
27+
"member_of_groups": {
28+
"count": 1,
29+
"edges": [
30+
{
31+
"node": {
32+
"display_label": "Super Administrators",
33+
"group_type": {
34+
"value": "default"
35+
},
36+
"id": "1816ebce-1cbe-2e96-3fc3-c5124c324bac",
37+
"roles": {
38+
"count": 1,
39+
"edges": [
40+
{
41+
"node": {
42+
"permissions": {
43+
"count": 2,
44+
"edges": [
45+
{
46+
"node": {
47+
"display_label": "super_admin 6",
48+
"identifier": {
49+
"value": "global:super_admin:allow_all"
50+
}
51+
}
52+
},
53+
{
54+
"node": {
55+
"display_label": "* * any 6",
56+
"identifier": {
57+
"value": "object:*:*:any:allow_all"
58+
}
59+
}
60+
}
61+
]
62+
}
63+
}
64+
}
65+
]
66+
}
67+
}
68+
}
69+
]
70+
},
71+
"__typename": "CoreAccount",
72+
"name": {
73+
"value": "admin",
74+
"updated_at": "2025-01-02T16:06:15.565985+00:00",
75+
"__typename": "TextAttribute"
76+
}
77+
}
78+
}
79+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"data": {
3+
"InfrahubInfo": {
4+
"version": "1.1.0"
5+
}
6+
}
7+
}

tests/unit/ctl/test_cli.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import json
12
import sys
23

34
import pytest
5+
from pytest_httpx._httpx_mock import HTTPXMock
46
from typer.testing import CliRunner
57

68
from infrahub_sdk.ctl.cli import app
79

10+
from .test_transform_app import read_fixture
11+
812
runner = CliRunner()
913

1014
requires_python_310 = pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10 or higher")
@@ -27,3 +31,58 @@ def test_validate_all_groups_have_names():
2731
assert app.registered_groups
2832
for group in app.registered_groups:
2933
assert group.name
34+
35+
36+
def test_version_command():
37+
result = runner.invoke(app, ["version"])
38+
assert result.exit_code == 0
39+
assert "Python SDK: v" in result.stdout
40+
41+
42+
def mock_common_responses(httpx_mock: HTTPXMock):
43+
httpx_mock.add_response(
44+
method="POST",
45+
url="http://mock/graphql/main",
46+
json=json.loads(read_fixture("infrahub_info.json", "info_cmd")),
47+
)
48+
httpx_mock.add_response(
49+
method="POST",
50+
url="http://mock/graphql/main",
51+
json=json.loads(read_fixture("account_profile.json", "info_cmd")),
52+
)
53+
54+
55+
def test_info_command_success(httpx_mock: HTTPXMock):
56+
mock_common_responses(httpx_mock)
57+
58+
result = runner.invoke(app, ["info"])
59+
assert result.exit_code == 0
60+
for expected in ["Connection Status", "Python Version", "SDK Version", "Infrahub Version"]:
61+
assert expected in result.stdout, f"'{expected}' not found in info command output"
62+
63+
64+
def test_info_command_failure():
65+
result = runner.invoke(app, ["info"])
66+
assert result.exit_code == 0
67+
assert "Connection Error" in result.stdout
68+
69+
70+
def test_info_detail_command_success(httpx_mock: HTTPXMock):
71+
mock_common_responses(httpx_mock)
72+
result = runner.invoke(app, ["info", "--detail"])
73+
assert result.exit_code == 0
74+
for expected in [
75+
"Connection Status",
76+
"Version Information",
77+
"Client Info",
78+
"Infrahub Info",
79+
"Groups:",
80+
"Super Administrators",
81+
]:
82+
assert expected in result.stdout, f"'{expected}' not found in detailed info command output"
83+
84+
85+
def test_info_detail_command_failure():
86+
result = runner.invoke(app, ["info", "--detail"])
87+
assert result.exit_code == 0
88+
assert "Error Reason" in result.stdout

0 commit comments

Comments
 (0)