From 93e615ffee181acd9c446d00f81093ae8e9a51df Mon Sep 17 00:00:00 2001 From: Raul Marquez Date: Sun, 8 Sep 2024 23:14:08 +0000 Subject: [PATCH] Adds test collection/suite/extras to applicable test cases api --- app/api/api_v1/endpoints/projects.py | 10 ++++++---- app/pics_applicable_test_cases.py | 24 +++++++++++++++++------- app/schemas/__init__.py | 8 +++++++- app/schemas/pics.py | 4 ++++ 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/api/api_v1/endpoints/projects.py b/app/api/api_v1/endpoints/projects.py index 5193eecb..373a11b2 100644 --- a/app/api/api_v1/endpoints/projects.py +++ b/app/api/api_v1/endpoints/projects.py @@ -281,13 +281,13 @@ def remove_pics_cluster_type( @router.get( - "/{id}/applicable_test_cases", response_model=schemas.PICSApplicableTestCases + "/{id}/applicable_test_cases", response_model=schemas.PICSApplicableTestCasesDetail ) def applicable_test_cases( *, db: Session = Depends(get_db), id: int, -) -> schemas.PICSApplicableTestCases: +) -> schemas.PICSApplicableTestCasesDetail: """Retrieve list of applicable test cases based on project identifier. Args: @@ -297,13 +297,15 @@ def applicable_test_cases( HTTPException: if no project exists for provided project id Returns: - PICSApplicableTestCases: List of applicable test cases + PICSApplicableTestCasesDetail: List of applicable test cases """ project = __project(db=db, id=id) project_data = Proj.from_orm(project) - return applicable_test_cases_list(pics=project_data.pics) + applicable_test_cases = applicable_test_cases_list(pics=project_data.pics) + + return applicable_test_cases def __project(db: Session, id: int) -> Project: diff --git a/app/pics_applicable_test_cases.py b/app/pics_applicable_test_cases.py index b5f81909..7fe38dd3 100644 --- a/app/pics_applicable_test_cases.py +++ b/app/pics_applicable_test_cases.py @@ -17,19 +17,19 @@ from loguru import logger -from app.schemas.pics import PICS, PICSApplicableTestCases +from app.schemas.pics import PICS, PICSApplicableTestCasesDetail from app.test_engine.models.test_declarations import TestCollectionDeclaration from app.test_engine.test_script_manager import test_script_manager -def applicable_test_cases_list(pics: PICS) -> PICSApplicableTestCases: +def applicable_test_cases_list(pics: PICS) -> PICSApplicableTestCasesDetail: """Returns the applicable test cases for this project given the set of PICS" Args: pics (PICS): set of pics to map against Returns: - PICSApplicableTestCases: List of test cases that are applicable + PICSApplicableTestCasesDetail: List of test cases that are applicable for this Project """ applicable_tests: list = [] @@ -38,7 +38,7 @@ def applicable_test_cases_list(pics: PICS) -> PICSApplicableTestCases: # If the user has not uploaded any PICS # i.e, there are no PICS associated with the project then return empty set logger.debug(f"Applicable test cases: {applicable_tests}") - return PICSApplicableTestCases(test_cases=applicable_tests) + return PICSApplicableTestCasesDetail(test_cases=applicable_tests) test_collections = test_script_manager.test_collections enabled_pics = set([item.number for item in pics.all_enabled_items()]) @@ -56,7 +56,7 @@ def applicable_test_cases_list(pics: PICS) -> PICSApplicableTestCases: applicable_tests.extend(applicable_remaining_tests) logger.debug(f"Applicable test cases: {applicable_tests}") - return PICSApplicableTestCases(test_cases=applicable_tests) + return PICSApplicableTestCasesDetail(test_cases=applicable_tests) def __applicable_test_cases( @@ -70,10 +70,20 @@ def __applicable_test_cases( if test_collection.mandatory == mandatory: for test_suite in test_collection.test_suites.values(): for test_case in test_suite.test_cases.values(): + test_case_trace = {} + test_case_trace[test_case.metadata["title"]] = { + "test_suite": test_suite.metadata["title"], + "test_collection": test_collection.name, + "mandatory": test_collection.mandatory, + "pics_required": True, + } if len(test_case.pics) == 0: # Test cases without pics required are always applicable - applicable_tests.append(test_case.metadata["title"]) + test_case_trace[test_case.metadata["title"]][ + "pics_required" + ] = False + applicable_tests.append(test_case_trace) elif len(test_case.pics) > 0: if test_case.pics.issubset(enabled_pics): - applicable_tests.append(test_case.metadata["title"]) + applicable_tests.append(test_case_trace) return applicable_tests diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py index 1616dbf9..d4198b23 100644 --- a/app/schemas/__init__.py +++ b/app/schemas/__init__.py @@ -23,7 +23,13 @@ OperatorToExport, OperatorUpdate, ) -from .pics import PICS, PICSApplicableTestCases, PICSCluster, PICSItem +from .pics import ( + PICS, + PICSApplicableTestCases, + PICSApplicableTestCasesDetail, + PICSCluster, + PICSItem, +) from .project import Project, ProjectCreate, ProjectInDB, ProjectUpdate from .test_case_execution import TestCaseExecution, TestCaseExecutionToExport from .test_case_metadata import TestCaseMetadata, TestCaseMetadataBase diff --git a/app/schemas/pics.py b/app/schemas/pics.py index 21dc0e67..2f78870b 100644 --- a/app/schemas/pics.py +++ b/app/schemas/pics.py @@ -41,5 +41,9 @@ class PICSApplicableTestCases(BaseModel): test_cases: list[str] +class PICSApplicableTestCasesDetail(BaseModel): + test_cases: list[dict] + + class PICSError(Exception): """Raised when an error occurs during execution."""