8000 fix(anta): get_json_results returns null instead of "None" by carl-baillargeon · Pull Request #531 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(anta): get_json_results returns null instead of "None" #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
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
6 changes: 2 additions & 4 deletions anta/result_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ def get_json_results(self) -> str:
Returns:
str: JSON dumps of the list of results
"""
res = []
for device in self._result_entries:
res.append({k: v if isinstance(v, list) else str(v) for k, v in device})
return json.dumps(res, indent=4)
result = [result.model_dump() for result in self._result_entries]
return json.dumps(result, indent=4)

def get_result_by_test(self, test_name: str) -> list[TestResult]:
"""
Expand Down
1 change: 1 addition & 0 deletions tests/lib/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _create(index: int = 0) -> TestResult:
test=f"VerifyTest{index}",
categories=["test"],
description=f"Verifies Test {index}",
custom_field=None,
)

return _create
Expand Down
16 changes: 12 additions & 4 deletions tests/units/result_manager/test__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,18 @@ def test_get_json_results(self, list_result_factory: Callable[[int], list[TestRe
test.result = "success"
result_manager.add_test_results(success_list)

res = result_manager.get_json_results()
assert isinstance(res, str)
# verifies it can be loaded as json
json.loads(res)
json_res = result_manager.get_json_results()
assert isinstance(json_res, str)

# Verifies it can be deserialized back to a list of dict with the correct values types
res = json.loads(json_res)
for test in res:
assert isinstance(test, dict)
assert isinstance(test.get("test"), str)
assert isinstance(test.get("categories"), list)
assert isinstance(test.get("description"), str)
assert test.get("custom_field") is None
assert test.get("result") == "success"

# TODO
# get_result_by_test
Expand Down
0