Skip to content
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
4 changes: 2 additions & 2 deletions kcidev/libs/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def dashboard_fetch_hardware_list(origin, use_json):
last_week = now - timedelta(days=7)
params = {
"origin": origin,
"endTimeStampInSeconds": int(now.timestamp()),
"startTimestampInSeconds": int(last_week.timestamp()),
"endTimestampInSeconds": str(int(now.timestamp())),
"startTimestampInSeconds": str(int(last_week.timestamp())),
}
logging.info(f"Fetching hardware list for origin: {origin}")
logging.debug(
Expand Down
14 changes: 8 additions & 6 deletions kcidev/subcommands/results/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,19 @@ def cmd_hardware_list(data, use_json):

if use_json:
hardware = [
{"name": hardware["hardware_name"], "compatibles": hardware["platform"]}
{
"name": hardware.get("hardware") or hardware["platform"],
"compatibles": hardware["platform"],
}
for hardware in data["hardware"]
]
kci_msg(hardware)
kci_msg(json.dumps(hardware))
else:
for hardware in data["hardware"]:
logging.debug(
f"Hardware: {hardware['hardware_name']} - {hardware['platform']}"
)
hardware_name = hardware.get("hardware") or hardware["platform"]
logging.debug(f"Hardware: {hardware_name} - {hardware['platform']}")
kci_msg_nonl("- name: ")
kci_msg_cyan(hardware["hardware_name"], nl=False)
kci_msg_cyan(hardware_name, nl=False)
kci_msg("")

kci_msg_nonl(" compatibles: ")
Expand Down
86 changes: 86 additions & 0 deletions tests/test_kcidev.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,92 @@ def test_kcidev_results_summary_history_import():
assert "/" in result # Should contain separators


def test_kcidev_results_hardware_list():
"""Test that hardware list command works and returns expected output format"""
command = [
"poetry",
"run",
"kci-dev",
"results",
"hardware",
"list",
"--origin",
"maestro",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)

print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout)
print("#### stderr ####")
print(result.stderr)

# Test should succeed
assert result.returncode == 0

# Should contain hardware entries with expected format
output_lines = result.stdout.strip().split("\n")

# Should have at least some hardware entries
assert len(output_lines) > 0

# Check format: lines should contain "- name:" and "compatibles:"
name_lines = [line for line in output_lines if line.strip().startswith("- name:")]
compatible_lines = [
line for line in output_lines if line.strip().startswith("compatibles:")
]

# Should have matching number of name and compatible lines
assert len(name_lines) > 0
assert len(compatible_lines) > 0
assert len(name_lines) == len(compatible_lines)


def test_kcidev_results_hardware_list_json():
"""Test that hardware list command works with JSON output"""
command = [
"poetry",
"run",
"kci-dev",
"results",
"hardware",
"list",
"--origin",
"maestro",
"--json",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)

print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout[:500] + "..." if len(result.stdout) > 500 else result.stdout)
print("#### stderr ####")
print(result.stderr)

# Test should succeed
assert result.returncode == 0

# Should be valid JSON
import json

try:
data = json.loads(result.stdout)
assert isinstance(data, list)

# Should have at least some hardware entries
assert len(data) > 0

# Each entry should have 'name' and 'compatibles' fields
for entry in data[:5]: # Check first 5 entries
assert "name" in entry
assert "compatibles" in entry
assert isinstance(entry["name"], str)
assert isinstance(entry["compatibles"], str)

except json.JSONDecodeError:
pytest.fail("Output is not valid JSON")


def test_clean():
# clean enviroment
shutil.rmtree("my-new-repo/")