in security-policies/dev/update_rule_status.py [0:0]
def get_integration_test_cases(benchmark_id):
"""
Given a benchmark_id looks up all the submodules, and retrieve the map declared as test_cases
:param benchmark_id: benchmark to look for integration tests
:return: Dictionary of test cases
"""
root_module_name = f"{test_cases_module_name}.{get_provider(benchmark_id)}"
if importlib.util.find_spec(root_module_name) is None:
# No test data found
return dict()
root_module = importlib.import_module(root_module_name)
modules = iter_modules(root_module.__path__)
tcs = dict()
for module in modules:
submodule = importlib.import_module("." + module.name, root_module.__name__)
if not hasattr(submodule, test_cases_variable_name):
print("Could not find test_cases in ", root_module.__name__, module.name)
continue
test_cases = getattr(submodule, test_cases_variable_name)
for _, tc in test_cases.items():
if test_cases_module_name not in type(tc).__module__ or getattr(tc, "rule_tag") is None:
continue
rule_number = tc.rule_tag.replace("CIS ", "")
if rule_number not in tcs:
tcs[rule_number] = {
"passed": False,
"failed": False,
}
tcs[rule_number][tc.expected] = True
return tcs