From 5410c969a863ea4ce5783674d941bada9560c092 Mon Sep 17 00:00:00 2001 From: patrickpa Date: Mon, 10 Jun 2024 16:24:24 +0200 Subject: [PATCH] Update tests to work with new schema restrictions Signed-off-by: patrickpa --- tests/data/demo_checker_bundle_extended.xqar | 29 ++++++++ tests/data/result_test_output.xqar | 5 +- tests/test_result.py | 76 +++++++++++++++++++- 3 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 tests/data/demo_checker_bundle_extended.xqar diff --git a/tests/data/demo_checker_bundle_extended.xqar b/tests/data/demo_checker_bundle_extended.xqar new file mode 100644 index 0000000..604b6a3 --- /dev/null +++ b/tests/data/demo_checker_bundle_extended.xqar @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/result_test_output.xqar b/tests/data/result_test_output.xqar index 9d4ed63..59d1129 100644 --- a/tests/data/result_test_output.xqar +++ b/tests/data/result_test_output.xqar @@ -1,8 +1,9 @@ - - + + + diff --git a/tests/test_result.py b/tests/test_result.py index 9c41f42..96bef97 100644 --- a/tests/test_result.py +++ b/tests/test_result.py @@ -1,10 +1,11 @@ import os import pytest from qc_baselib.models import config, result -from qc_baselib import Result, IssueSeverity +from qc_baselib import Result, IssueSeverity, StatusType DEMO_REPORT_PATH = "tests/data/demo_checker_bundle.xqar" +EXTENDED_DEMO_REPORT_PATH = "tests/data/demo_checker_bundle_extended.xqar" EXAMPLE_OUTPUT_REPORT_PATH = "tests/data/result_test_output.xqar" TEST_REPORT_OUTPUT_PATH = "tests/result_test_output.xqar" @@ -22,6 +23,12 @@ def test_load_result_from_file() -> None: assert len(result._report_results.to_xml()) > 0 +def test_load_result_from_extended_file() -> None: + result = Result() + result.load_from_file(EXTENDED_DEMO_REPORT_PATH) + assert len(result._report_results.to_xml()) > 0 + + def test_result_write() -> None: result = Result() @@ -40,11 +47,21 @@ def test_result_write() -> None: summary="Executed evaluation", ) + rule_uid = result.register_rule( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + emanating_entity="test.com", + standard="qc", + definition_setting="1.0.0", + rule_full_name="qwerty.qwerty", + ) + issue_id = result.register_issue( checker_bundle_name="TestBundle", checker_id="TestChecker", description="Issue found at odr", level=IssueSeverity.INFORMATION, + rule_uid=rule_uid, ) result.add_file_location( @@ -64,6 +81,12 @@ def test_result_write() -> None: description="Location for issue", ) + result.set_checker_status( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + status=StatusType.COMPLETED, + ) + result.write_to_file(TEST_REPORT_OUTPUT_PATH) example_xml_text = "" @@ -148,11 +171,21 @@ def test_result_register_issue_id_generation() -> None: summary="Executed evaluation", ) + rule_uid = result.register_rule( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + emanating_entity="test.com", + standard="qc", + definition_setting="1.0.0", + rule_full_name="qwerty.qwerty", + ) + issue_id_0 = result.register_issue( checker_bundle_name="TestBundle", checker_id="TestChecker", description="Issue found at odr", level=IssueSeverity.INFORMATION, + rule_uid=rule_uid, ) issue_id_1 = result.register_issue( @@ -160,7 +193,48 @@ def test_result_register_issue_id_generation() -> None: checker_id="TestChecker", description="Issue found at odr", level=IssueSeverity.INFORMATION, + rule_uid=rule_uid, ) assert issue_id_0 != issue_id_1 assert issue_id_0 == issue_id_1 - 1 + + +def test_create_issue_load_id() -> None: + result = Result() + + result.register_checker_bundle( + name="TestBundle", + build_date="2024-05-31", + description="Example checker bundle", + version="0.0.1", + summary="Tested example checkers", + ) + + result.register_checker( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + description="Test checker", + summary="Executed evaluation", + ) + + rule_uid = result.register_rule( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + emanating_entity="test.com", + standard="qc", + definition_setting="1.0.0", + rule_full_name="qwerty.qwerty", + ) + + assert rule_uid == "test.com:qc:1.0.0:qwerty.qwerty" + + issue_id = result.register_issue( + checker_bundle_name="TestBundle", + checker_id="TestChecker", + description="Issue found at odr", + level=IssueSeverity.INFORMATION, + rule_uid=rule_uid, + ) + + assert issue_id == 0