Updating test_scanner_uploader to support multiple folders

Change-Id: Icc8dae6a0f2eba75f3b98e481d140f5e30277914
This commit is contained in:
croy
2025-01-24 11:44:29 -05:00
parent c0be775831
commit a5d75dd54f
3 changed files with 30 additions and 7 deletions

View File

@ -25,6 +25,15 @@ class ConfigurationManagerClass:
self.rest_api_config: RestAPIConfig = None
self.configuration_locations_manager = None
def is_config_loaded(self) -> bool:
"""
This function will return true if the configurations are already loaded.
Returns:
"""
return self.loaded
def load_configs(self, config_file_locations: ConfigurationFileLocationsManager):
"""
This function will load all the config files.

View File

@ -1,3 +1,5 @@
from typing import List
import pytest
from framework.database.objects.testcase import TestCase
from framework.database.operations.capability_operation import CapabilityOperation
@ -11,8 +13,8 @@ class TestScannerUploader:
Class for Scanning tests and uploading.
"""
def __init__(self, test_folder: str):
self.test_folder = test_folder
def __init__(self, test_folders: List[str]):
self.test_folders = test_folders
def scan_and_upload_tests(self):
"""
@ -23,9 +25,17 @@ class TestScannerUploader:
test_info_operation = TestInfoOperation()
scanned_tests = self.scan_for_tests()
filtered_test_cases = [test for test in scanned_tests if test.get_pytest_node_id().startswith(self.test_folder)]
# Filter to find only the test cases in the desired folders.
filtered_test_cases = []
for test in scanned_tests:
if any(test.get_pytest_node_id().startswith(test_folder) for test_folder in self.test_folders):
filtered_test_cases.append(test)
# Upload/Update the test cases in the database
for test in filtered_test_cases:
print(f"Inserting/Updating - {test.get_test_suite()}::{test.get_test_name()}")
test_info_id = test_info_operation.get_info_test_id(test.get_test_name(), test.get_test_suite())
if not test_info_id:
test_info_id = test_info_operation.insert_test(test)
@ -101,11 +111,14 @@ class TestScannerUploader:
capabilities = test.get_markers()
for capability in capabilities:
capability_id = capability_operation.get_capability_by_marker(capability).get_capability_id()
# if capability does not exist, add it
if capability_id == -1:
capability_object = capability_operation.get_capability_by_marker(capability)
# If capability does not exist, raise an exception
if capability_object == -1:
raise ValueError(f"No capability with name {capability} exists")
capability_id = capability_object.get_capability_id()
mapping_id = capability_test_operation.get_id(capability_id, test_info_id)
# mapping does not exist, add new one
if mapping_id == -1:

View File

@ -18,5 +18,6 @@ if __name__ == '__main__':
configuration_locations_manager.set_configs_from_options_parser(parser)
ConfigurationManager.load_configs(configuration_locations_manager)
test_scanner_uploader = TestScannerUploader("testcases")
folders_to_scan = ["testcases"]
test_scanner_uploader = TestScannerUploader(folders_to_scan)
test_scanner_uploader.scan_and_upload_tests()