Skip to content

Commit

Permalink
Merge branch 'main' into feature/74_phase3-add_python_tests_model_cla…
Browse files Browse the repository at this point in the history
…sses
  • Loading branch information
rquidute authored Nov 14, 2023
2 parents b914e19 + a271912 commit 939bf15
Show file tree
Hide file tree
Showing 21 changed files with 1,216 additions and 741 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Unit Tests

on:
pull_request_target:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Fetch yaml tests and runner
run: |
source $(poetry env info --path)/bin/activate
./test_collections/sdk_tests/fetch_sdk_tests_and_runner.sh
./test_collections/sdk_tests/scripts/fetch_sdk_tests_and_runner.sh
env:
SERVER_NAME: localhost
SERVER_HOST: http://localhost
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Adding the new column collection_id
Revision ID: 96ee37627a48
Revises: 9996326cbd1d
Create Date: 2023-08-15 14:42:39.893126
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "96ee37627a48"
down_revision = "9996326cbd1d"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"testsuiteexecution", sa.Column("collection_id", sa.String(), nullable=False)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("testsuiteexecution", "collection_id")
# ### end Alembic commands ###
8 changes: 4 additions & 4 deletions app/api/api_v1/endpoints/test_run_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
router = APIRouter()


@router.get("/", response_model=List[schemas.TestRunConfig])
@router.get("/", response_model=List[schemas.TestRunConfig], deprecated=True)
def read_test_run_configs(
db: Session = Depends(get_db),
skip: int = 0,
Expand All @@ -38,7 +38,7 @@ def read_test_run_configs(
return crud.test_run_config.get_multi(db, skip=skip, limit=limit)


@router.post("/", response_model=schemas.TestRunConfig)
@router.post("/", response_model=schemas.TestRunConfig, deprecated=True)
def create_test_run_config(
*,
db: Session = Depends(get_db),
Expand All @@ -56,7 +56,7 @@ def create_test_run_config(
)


@router.put("/{id}", response_model=schemas.TestRunConfig)
@router.put("/{id}", response_model=schemas.TestRunConfig, deprecated=True)
def update_test_run_config(
*,
db: Session = Depends(get_db),
Expand All @@ -78,7 +78,7 @@ def update_test_run_config(
return test_run_config


@router.get("/{id}", response_model=schemas.TestRunConfig)
@router.get("/{id}", response_model=schemas.TestRunConfig, deprecated=True)
def read_test_run_config(
*,
db: Session = Depends(get_db),
Expand Down
66 changes: 53 additions & 13 deletions app/api/api_v1/endpoints/test_run_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
from app.test_engine import TEST_ENGINE_ABORTING_TESTING_MESSAGE
from app.test_engine.test_runner import AbortError, LoadingError, TestRunner
from app.test_engine.test_script_manager import TestNotFound
from app.utils import (
formated_datetime_now_str,
remove_title_date,
selected_tests_from_execution,
)
from app.version import version_information

router = APIRouter()
Expand Down Expand Up @@ -72,21 +77,12 @@ def create_test_run_execution(
*,
db: Session = Depends(get_db),
test_run_execution_in: schemas.TestRunExecutionCreate,
selected_tests: Optional[schemas.TestSelection] = None,
selected_tests: schemas.TestSelection,
) -> TestRunExecution:
"""
Create new test run execution.
"""
test_run_config_present = test_run_execution_in.test_run_config_id is not None
selected_tests_present = selected_tests is not None

if test_run_config_present and selected_tests_present:
msg = "Only either test_run_config_id or selected_tests must be present"
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail=msg)
"""Create a new test run execution."""

if not test_run_config_present and not selected_tests_present:
msg = "Either test_run_config_id or selected_tests must be present"
raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail=msg)
# TODO: Remove test_run_config completely from the project
test_run_execution_in.test_run_config_id = None

test_run_execution = crud.test_run_execution.create(
db=db, obj_in=test_run_execution_in, selected_tests=selected_tests
Expand Down Expand Up @@ -230,6 +226,50 @@ def unarchive(
return crud.test_run_execution.unarchive(db=db, db_obj=test_run_execution)


@router.post("/{id}/repeat", response_model=schemas.TestRunExecutionWithChildren)
def repeat_test_run_execution(
*, db: Session = Depends(get_db), id: int, title: Optional[str] = None
) -> TestRunExecution:
"""Repeat a test run execution by id.
Args:
id (int): test run execution id
title (str): Optional title to the repeated test run execution. If not provided,
the old title will be used with the date and time updated.
Raises:
HTTPException: if no test run execution exists for the provided id
Returns:
TestRunExecution: new test run execution with the same test cases from id
"""
execution_to_repeat = crud.test_run_execution.get(db=db, id=id)
if not execution_to_repeat:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TestRunExecution not found"
)

if title is None:
# If no title is provided, the old title will be used without data info
title = remove_title_date(execution_to_repeat.title)

date_now = formated_datetime_now_str()
title += date_now

test_run_execution_in = schemas.TestRunExecutionCreate(title=title)
test_run_execution_in.description = execution_to_repeat.description
test_run_execution_in.project_id = execution_to_repeat.project_id
test_run_execution_in.operator_id = execution_to_repeat.operator_id
# TODO: Remove test_run_config completely from the project
test_run_execution_in.test_run_config_id = None

selected_tests = selected_tests_from_execution(execution_to_repeat)

return crud.test_run_execution.create(
db=db, obj_in=test_run_execution_in, selected_tests=selected_tests
)


@router.delete("/{id}", response_model=schemas.TestRunExecutionInDBBase)
def remove_test_run_execution(
*,
Expand Down
6 changes: 3 additions & 3 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool:
# Logging
LOGGING_PATH: str = "./logs"
LOGGING_FILENAME: str = "{time:YYYY-MM-DD}.log"
LOGGING_LEVEL: str = "debug"
LOGGING_LEVEL: str = "info"
LOGGING_ROTATION: str = "20 days"
LOGGING_RETENTION: str = "1 months"
LOGGING_FORMAT: str = (
Expand All @@ -113,9 +113,9 @@ def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool:

# SDK Docker Image
SDK_DOCKER_IMAGE: str = "connectedhomeip/chip-cert-bins"
SDK_DOCKER_TAG: str = "19771ed7101321d68b87d05201d42d00adf5368f"
SDK_DOCKER_TAG: str = "f06d9520d02d68076c5accbf839f168cda89c47c"
# SDK SHA: used to fetch test YAML from SDK.
SDK_SHA: str = "19771ed7101321d68b87d05201d42d00adf5368f"
SDK_SHA: str = "f06d9520d02d68076c5accbf839f168cda89c47c"

class Config:
case_sensitive = True
Expand Down
1 change: 1 addition & 0 deletions app/models/test_suite_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestSuiteExecution(Base):
id: Mapped[int] = mapped_column(primary_key=True, index=True)
public_id: Mapped[str] = mapped_column(nullable=False)
execution_index: Mapped[int] = mapped_column(nullable=False)
collection_id: Mapped[str] = mapped_column(nullable=False)

state: Mapped[TestStateEnum] = mapped_column(
Enum(TestStateEnum), nullable=False, default=TestStateEnum.PENDING
Expand Down
2 changes: 1 addition & 1 deletion app/otbr_manager/otbr_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def start_device(self, config: ThreadAutoConfig) -> bool:

except (asyncio.exceptions.TimeoutError, ThreadBorderRouterError):
err_msg = "Border router does not start properly for " + self.__docker_image
logger.debug(self.__otbr_docker.logs().decode("utf-8"))
logger.warning(self.__otbr_docker.logs().decode("utf-8"))
logger.error(err_msg)
self.destroy_device()
raise ThreadBorderRouterError(err_msg)
Expand Down
1 change: 1 addition & 0 deletions app/schemas/test_suite_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TestSuiteExecutionBase(BaseModel):
state: TestStateEnum
public_id: str
execution_index: int
collection_id: str


# Properties shared by models stored in DB
Expand Down
9 changes: 7 additions & 2 deletions app/test_engine/test_script_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def __pending_test_suites_for_test_collection(
test_suite = test_collection.test_suites[test_suite_id]

# Create pending test suite
test_suite_execution = self.__pending_test_suite_execution(test_suite)
test_suite_execution = self.__pending_test_suite_execution(
test_suite, test_collection
)

# Create pending test cases
test_cases = self.___pending_test_cases_for_test_suite(
Expand All @@ -130,6 +132,7 @@ def __pending_test_suites_for_test_collection(
def __pending_test_suite_execution(
self,
test_suite: TestSuiteDeclaration,
test_collection: TestCollectionDeclaration,
) -> TestSuiteExecution:
"""
This will create a DB entry for test suite.
Expand All @@ -139,7 +142,9 @@ def __pending_test_suite_execution(
metadata = self.__find_or_create_test_suite_metadata(test_suite=test_suite)

test_suite_execution = TestSuiteExecution(
public_id=metadata.public_id, test_suite_metadata=metadata
public_id=metadata.public_id,
test_suite_metadata=metadata,
collection_id=test_collection.name,
)
return test_suite_execution

Expand Down
5 changes: 5 additions & 0 deletions app/tests/api/api_v1/test_test_run_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#
from http import HTTPStatus

import pytest
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session

from app.core.config import settings
from app.tests.utils.test_run_config import create_random_test_run_config


@pytest.mark.deprecated("The test_run_config is now deprecated along with this test")
def test_create_test_run_config(client: TestClient, db: Session) -> None:
data = {
"name": "Foo",
Expand Down Expand Up @@ -50,6 +52,7 @@ def test_create_test_run_config(client: TestClient, db: Session) -> None:
assert "id" in content


@pytest.mark.deprecated("The test_run_config is now deprecated along with this test")
def test_create_test_run_config_invalid_selection(
client: TestClient, db: Session
) -> None:
Expand Down Expand Up @@ -77,6 +80,7 @@ def test_create_test_run_config_invalid_selection(
assert "detail" in content


@pytest.mark.deprecated("The test_run_config is now deprecated along with this test")
def test_read_test_run_config(client: TestClient, db: Session) -> None:
test_run_config = create_random_test_run_config(db)
response = client.get(
Expand All @@ -90,6 +94,7 @@ def test_read_test_run_config(client: TestClient, db: Session) -> None:
assert content["selected_tests"] == test_run_config.selected_tests


@pytest.mark.deprecated("The test_run_config is now deprecated along with this test")
def test_update_test_run_config(client: TestClient, db: Session) -> None:
test_run_config = create_random_test_run_config(db)
data = {"name": "Updated Name"}
Expand Down
Loading

0 comments on commit 939bf15

Please sign in to comment.