Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
)
from kubernetes_asyncio.client.models import V1ObjectMeta, V1ObjectReference

from jumpstarter_cli_admin.test_utils import json_equal

from .create import create
from jumpstarter.config.client import ClientConfigV1Alpha1, ClientConfigV1Alpha1Drivers
from jumpstarter.config.common import ObjectMeta
Expand Down Expand Up @@ -183,7 +185,7 @@ def test_create_client(
# With JSON output
result = runner.invoke(create, ["client", CLIENT_NAME, "--nointeractive", "--output", "json"])
assert result.exit_code == 0
assert result.output == CLIENT_JSON
assert json_equal(result.output, CLIENT_JSON)
mock_save_client.assert_not_called()
mock_save_client.reset_mock()

Expand Down Expand Up @@ -348,7 +350,7 @@ def test_create_exporter(
create, ["exporter", EXPORTER_NAME, "--label", "foo=bar", "--nointeractive", "--output", "json"]
)
assert result.exit_code == 0
assert result.output == EXPORTER_JSON
assert json_equal(result.output, EXPORTER_JSON)
save_exporter_mock.assert_not_called()
save_exporter_mock.reset_mock()

Expand Down
20 changes: 11 additions & 9 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from kubernetes_asyncio.client.exceptions import ApiException
from kubernetes_asyncio.client.models import V1Condition, V1ObjectMeta, V1ObjectReference

from jumpstarter_cli_admin.test_utils import json_equal

from .get import get


Expand Down Expand Up @@ -95,7 +97,7 @@ def test_get_client(_load_kube_config_mock, get_client_mock: AsyncMock):
get_client_mock.return_value = TEST_CLIENT
result = runner.invoke(get, ["client", "test", "--output", "json"])
assert result.exit_code == 0
assert result.output == TEST_CLIENT_JSON
assert json_equal(result.output, TEST_CLIENT_JSON)
get_client_mock.reset_mock()

# Get a single client YAML output
Expand Down Expand Up @@ -247,7 +249,7 @@ def test_get_clients(_load_kube_config_mock, list_clients_mock: AsyncMock):
list_clients_mock.return_value = CLIENTS_LIST
result = runner.invoke(get, ["clients", "--output", "json"])
assert result.exit_code == 0
assert result.output == CLIENTS_LIST_JSON
assert json_equal(result.output, CLIENTS_LIST_JSON)
list_clients_mock.reset_mock()

# List clients YAML output
Expand Down Expand Up @@ -275,7 +277,7 @@ def test_get_clients(_load_kube_config_mock, list_clients_mock: AsyncMock):
list_clients_mock.return_value = V1Alpha1ClientList(items=[])
result = runner.invoke(get, ["clients", "--output", "json"])
assert result.exit_code == 0
assert result.output == CLIENTS_LIST_EMPTY_JSON
assert json_equal(result.output, CLIENTS_LIST_EMPTY_JSON)
list_clients_mock.reset_mock()

# No clients found YAML output
Expand Down Expand Up @@ -352,7 +354,7 @@ def test_get_exporter(_load_kube_config_mock, get_exporter_mock: AsyncMock):
get_exporter_mock.return_value = TEST_EXPORTER
result = runner.invoke(get, ["exporter", "test", "--output", "json"])
assert result.exit_code == 0
assert result.output == TEST_EXPORTER_JSON
assert json_equal(result.output, TEST_EXPORTER_JSON)
get_exporter_mock.reset_mock()

# Get a single exporter YAML output
Expand Down Expand Up @@ -467,7 +469,7 @@ def test_get_exporter_devices(_load_kube_config_mock, get_exporter_mock: AsyncMo
get_exporter_mock.return_value = TEST_EXPORTER_DEVICES
result = runner.invoke(get, ["exporter", "test", "--devices", "--output", "json"])
assert result.exit_code == 0
assert result.output == TEST_EXPORTER_DEVICES_JSON
assert json_equal(result.output, TEST_EXPORTER_DEVICES_JSON)
get_exporter_mock.reset_mock()

# Returns exporter YAML output
Expand Down Expand Up @@ -612,7 +614,7 @@ def test_get_exporters(_load_kube_config_mock, list_exporters_mock: AsyncMock):
list_exporters_mock.return_value = EXPORTERS_LIST
result = runner.invoke(get, ["exporters", "--output", "json"])
assert result.exit_code == 0
assert result.output == EXPORTERS_LIST_JSON
assert json_equal(result.output, EXPORTERS_LIST_JSON)
list_exporters_mock.reset_mock()

# List exporters YAML output
Expand Down Expand Up @@ -780,7 +782,7 @@ def test_get_exporters_devices(_load_kube_config_mock, list_exporters_mock: Asyn
list_exporters_mock.return_value = EXPORTER_DEVICES_LIST
result = runner.invoke(get, ["exporters", "--devices", "--output", "json"])
assert result.exit_code == 0
assert result.output == EXPORTERS_DEVICES_LIST_JSON
assert json_equal(result.output, EXPORTERS_DEVICES_LIST_JSON)
list_exporters_mock.reset_mock()

# List exporters YAML output
Expand Down Expand Up @@ -971,7 +973,7 @@ def test_get_lease(_load_kube_config_mock, get_lease_mock: AsyncMock):
get_lease_mock.return_value = FINISHED_LEASE
result = runner.invoke(get, ["lease", "82a8ac0d-d7ff-4009-8948-18a3c5c607b2", "--output", "json"])
assert result.exit_code == 0
assert result.output == FINISHED_LEASE_JSON
assert json_equal(result.output, FINISHED_LEASE_JSON)
get_lease_mock.reset_mock()

# Get a finished lease YAML output
Expand Down Expand Up @@ -1173,7 +1175,7 @@ def test_get_leases(_load_kube_config_mock, list_leases_mock: AsyncMock):
list_leases_mock.return_value = V1Alpha1LeaseList(items=[IN_PROGRESS_LEASE, FINISHED_LEASE])
result = runner.invoke(get, ["leases", "--output", "json"])
assert result.exit_code == 0
assert result.output == LEASES_LIST_JSON
assert json_equal(result.output, LEASES_LIST_JSON)
list_leases_mock.reset_mock()

# Found leases YAML output
Expand Down
17 changes: 17 additions & 0 deletions packages/jumpstarter-cli-admin/jumpstarter_cli_admin/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json


def json_equal(a: str, b: str) -> bool:
def _parse(s: str):
try:
data = json.loads(s)
except ValueError:
return object()
if isinstance(data, str):
try:
data = json.loads(data)
except ValueError:
pass
return data

return _parse(a) == _parse(b)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def wrapped(*args, **kwargs):

def handle_exceptions_with_reauthentication(login_func):
"""Decorator to handle exceptions in blocking functions."""

def decorator(func):
@wraps(func)
def wrapped(*args, **kwargs):
Expand All @@ -67,6 +68,7 @@ def wrapped(*args, **kwargs):
raise # if it was already a click exception from the cli commands, just re-raise it
except Exception:
raise

return wrapped

return decorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def model_print( # noqa: C901

match output:
case OutputMode.JSON:
console.print(
model.model_dump_json(
indent=4,
console.print_json(
data=model.model_dump_json(
by_alias=True,
)
),
indent=4,
)
case OutputMode.YAML:
console.print(
Expand Down
Loading