Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #292: Adds test collection/suite/extras to applicable test cases api #140

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/api/api_v1/endpoints/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
24 changes: 17 additions & 7 deletions app/pics_applicable_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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()])
Expand All @@ -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(
Expand All @@ -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
8 changes: 7 additions & 1 deletion app/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/schemas/pics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Loading