Skip to content

Commit

Permalink
Update conversion script and add test
Browse files Browse the repository at this point in the history
Signed-off-by: Rodolfo Olivieri <[email protected]>
  • Loading branch information
r0x0d committed Nov 8, 2023
1 parent 326abc2 commit 3278b71
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ disable=
consider-using-f-string,
consider-using-with,
unspecified-encoding,
line-too-long
line-too-long,
# Temporary solution
duplicate-code

[REPORTS]

Expand Down
9 changes: 6 additions & 3 deletions scripts/conversion_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,15 @@ def parse_migration_results():
with open(C2R_MIGRATION_RESULTS_FILE) as handler:
contents = json.load(handler)

activities = contents["activities"]
if not contents:
return False

activities = contents.get("activities", [{}])
# Pick the latest run as it is the only one that matters for the decision
# process.
latest_run = activities[-1]

return latest_run["success"]
return latest_run.get("success", False)


def update_insights_inventory():
Expand Down Expand Up @@ -428,7 +431,6 @@ def main():
setup_convert2rhel(required_files)
install_convert2rhel()
run_convert2rhel()
update_insights_inventory()

# Gather JSON & Textual report
data = gather_json_report()
Expand All @@ -446,6 +448,7 @@ def main():
# Insights.
output.message = generate_report_message(migration_result, highest_level)
output.entries = transform_raw_data(data)
update_insights_inventory()
print("Conversion script finish successfully!")
except ProcessError as exception:
print(exception.report)
Expand Down
56 changes: 56 additions & 0 deletions tests/conversion_script/test_migration_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json
from mock import patch
import pytest
from scripts.conversion_script import parse_migration_results


def test_no_migration_results(tmpdir):
migration_result_file = tmpdir.join("migration_result")
with patch(
"scripts.conversion_script.C2R_MIGRATION_RESULTS_FILE",
str(migration_result_file),
):
assert not parse_migration_results()


@pytest.mark.parametrize(
("content", "expected"),
(
(
{"activities": [{"success": True}]},
True,
),
(
{"activities": [{"success": False}]},
False,
),
(
{"activities": [{"success": False}, {"success": True}]},
True,
),
(
{"activities": [{"success": True}, {"success": False}]},
False,
),
(
{"activities": [{}]},
False,
),
(
{},
False,
),
(
None,
False,
),
),
)
def test_migration_results_content(content, expected, tmpdir):
migration_result_file = tmpdir.join("migration_result")
migration_result_file.write(json.dumps(content, indent=4))
with patch(
"scripts.conversion_script.C2R_MIGRATION_RESULTS_FILE",
str(migration_result_file),
):
assert parse_migration_results() == expected

0 comments on commit 3278b71

Please sign in to comment.