Skip to content

Commit

Permalink
Fixing unit tests, removing test_run_config completely and related ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
antonio-amjr committed Nov 22, 2023
1 parent 040ebe5 commit dd71236
Show file tree
Hide file tree
Showing 25 changed files with 644 additions and 823 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Removing unnecessary TestRunConfig
Revision ID: 3189c039e59b
Revises: 96ee37627a48
Create Date: 2023-11-22 17:52:57.970522
"""
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

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


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_testrunexecution_test_run_config_id_testrunconfig",
"testrunexecution",
type_="foreignkey",
)
op.drop_column("testrunexecution", "test_run_config_id")
op.drop_index("ix_testrunconfig_id", table_name="testrunconfig")
op.drop_table("testrunconfig")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"testrunconfig",
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("dut_name", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column(
"created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=False
),
sa.Column(
"selected_tests",
postgresql.JSON(astext_type=sa.Text()),
autoincrement=False,
nullable=False,
),
sa.PrimaryKeyConstraint("id", name="pk_testrunconfig"),
)
op.create_index("ix_testrunconfig_id", "testrunconfig", ["id"], unique=False)
op.add_column(
"testrunexecution",
sa.Column(
"test_run_config_id", sa.INTEGER(), autoincrement=False, nullable=True
),
)
op.create_foreign_key(
"fk_testrunexecution_test_run_config_id_testrunconfig",
"testrunexecution",
"testrunconfig",
["test_run_config_id"],
["id"],
)
# ### end Alembic commands ###
4 changes: 0 additions & 4 deletions app/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
projects,
test_collections,
test_harness_backend_version,
test_run_configs,
test_run_executions,
utils,
)
Expand All @@ -39,9 +38,6 @@
prefix="/test_run_executions",
tags=["test_run_executions"],
)
api_router.include_router(
test_run_configs.router, prefix="/test_run_configs", tags=["test_run_configs"]
)

api_router.include_router(test_harness_backend_version.router, tags=["version"])
api_router.include_router(utils.router, prefix="/utils", tags=["utils"])
Expand Down
96 changes: 0 additions & 96 deletions app/api/api_v1/endpoints/test_run_configs.py

This file was deleted.

16 changes: 7 additions & 9 deletions app/api/api_v1/endpoints/test_run_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ def create_test_run_execution(
"""
Create new test run execution.
"""
test_run_execution_in.selected_tests = selected_tests
test_run_execution = crud.test_run_execution.create(
db=db, obj_in=test_run_execution_in
test_run_execution = crud.test_run_execution.create_with_selected_tests(
db=db, obj_in=test_run_execution_in, selected_tests=selected_tests
)
return test_run_execution

Expand Down Expand Up @@ -259,13 +258,12 @@ def repeat_test_run_execution(
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
test_run_execution_in.selected_tests = selected_tests_from_execution(
execution_to_repeat
)
# TODO: Remove test_run_config completely from the project
test_run_execution_in.test_run_config_id = None

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


@router.delete("/{id}", response_model=schemas.TestRunExecutionInDBBase)
Expand Down
1 change: 0 additions & 1 deletion app/crud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .crud_project import project
from .crud_test_case_execution import test_case_execution
from .crud_test_case_metadata import test_case_metadata
from .crud_test_run_config import test_run_config
from .crud_test_run_execution import test_run_execution
from .crud_test_step_execution import test_step_execution
from .crud_test_suite_execution import test_suite_execution
Expand Down
42 changes: 0 additions & 42 deletions app/crud/crud_test_run_config.py

This file was deleted.

24 changes: 15 additions & 9 deletions app/crud/crud_test_run_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

from app.crud import operator as crud_operator
from app.crud import project as crud_project
from app.crud import test_run_config as crud_test_run_config
from app.crud.base import CRUDBaseCreate, CRUDBaseDelete, CRUDBaseRead
from app.models import Project, TestCaseExecution, TestRunExecution, TestSuiteExecution
from app.schemas import (
TestRunConfigCreate,
SelectedTests,
TestRunExecutionToExport,
TestRunExecutionToImport,
)
Expand Down Expand Up @@ -176,9 +175,22 @@ def create(

test_run_execution = super().create(db=db, obj_in=obj_in)

db.commit()
db.refresh(test_run_execution)
return test_run_execution

def create_with_selected_tests(
self,
db: Session,
obj_in: TestRunExecutionCreate,
selected_tests: SelectedTests,
**kwargs: Optional[dict],
) -> TestRunExecution:
test_run_execution = self.create(db, obj_in=obj_in, **kwargs)

test_suites = (
test_script_manager.pending_test_suite_executions_for_selected_tests(
obj_in.selected_tests
selected_tests
)
)

Expand Down Expand Up @@ -258,12 +270,6 @@ def import_execution(
)
imported_execution.operator_id = operator_id

if execution.test_run_config:
test_run_config = crud_test_run_config.create(
db=db, obj_in=TestRunConfigCreate(**execution.test_run_config.__dict__)
)
imported_execution.test_run_config_id = test_run_config.id

imported_model = TestRunExecution(**jsonable_encoder(imported_execution))

db.add(imported_model)
Expand Down
1 change: 0 additions & 1 deletion app/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from app.models.project import Project # noqa
from app.models.test_case_execution import TestCaseExecution # noqa
from app.models.test_case_metadata import TestCaseMetadata # noqa
from app.models.test_run_config import TestRunConfig # noqa
from app.models.test_run_execution import TestRunExecution # noqa
from app.models.test_step_execution import TestStepExecution # noqa
from app.models.test_suite_execution import TestSuiteExecution # noqa
Expand Down
1 change: 0 additions & 1 deletion app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .test_case_execution import TestCaseExecution
from .test_case_metadata import TestCaseMetadata
from .test_enums import TestStateEnum
from .test_run_config import TestRunConfig
from .test_run_execution import TestRunExecution
from .test_step_execution import TestStepExecution
from .test_suite_execution import TestSuiteExecution
Expand Down
40 changes: 0 additions & 40 deletions app/models/test_run_config.py

This file was deleted.

7 changes: 0 additions & 7 deletions app/models/test_run_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
if TYPE_CHECKING:
from .operator import Operator # noqa: F401
from .project import Project # noqa: F401
from .test_run_config import TestRunConfig # noqa: F401


class TestRunExecution(Base):
Expand All @@ -53,12 +52,6 @@ class TestRunExecution(Base):

description: Mapped[Optional[str]] = mapped_column(default=None, nullable=True)

test_run_config_id: Mapped[Optional[int]] = mapped_column(
ForeignKey("testrunconfig.id"), nullable=True
)
test_run_config: Mapped["TestRunConfig"] = relationship(
"TestRunConfig", back_populates="test_run_executions"
)
log: Mapped[list[TestRunLogEntry]] = mapped_column(
MutableList.as_mutable(PydanticListType(TestRunLogEntry)),
default=[],
Expand Down
Loading

0 comments on commit dd71236

Please sign in to comment.