Skip to content

Commit dd71236

Browse files
committed
Fixing unit tests, removing test_run_config completely and related changes
1 parent 040ebe5 commit dd71236

25 files changed

+644
-823
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Removing unnecessary TestRunConfig
2+
3+
Revision ID: 3189c039e59b
4+
Revises: 96ee37627a48
5+
Create Date: 2023-11-22 17:52:57.970522
6+
7+
"""
8+
import sqlalchemy as sa
9+
from sqlalchemy.dialects import postgresql
10+
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision = "3189c039e59b"
15+
down_revision = "96ee37627a48"
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.drop_constraint(
23+
"fk_testrunexecution_test_run_config_id_testrunconfig",
24+
"testrunexecution",
25+
type_="foreignkey",
26+
)
27+
op.drop_column("testrunexecution", "test_run_config_id")
28+
op.drop_index("ix_testrunconfig_id", table_name="testrunconfig")
29+
op.drop_table("testrunconfig")
30+
# ### end Alembic commands ###
31+
32+
33+
def downgrade():
34+
# ### commands auto generated by Alembic - please adjust! ###
35+
op.create_table(
36+
"testrunconfig",
37+
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
38+
sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False),
39+
sa.Column("dut_name", sa.VARCHAR(), autoincrement=False, nullable=False),
40+
sa.Column(
41+
"created_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=False
42+
),
43+
sa.Column(
44+
"selected_tests",
45+
postgresql.JSON(astext_type=sa.Text()),
46+
autoincrement=False,
47+
nullable=False,
48+
),
49+
sa.PrimaryKeyConstraint("id", name="pk_testrunconfig"),
50+
)
51+
op.create_index("ix_testrunconfig_id", "testrunconfig", ["id"], unique=False)
52+
op.add_column(
53+
"testrunexecution",
54+
sa.Column(
55+
"test_run_config_id", sa.INTEGER(), autoincrement=False, nullable=True
56+
),
57+
)
58+
op.create_foreign_key(
59+
"fk_testrunexecution_test_run_config_id_testrunconfig",
60+
"testrunexecution",
61+
"testrunconfig",
62+
["test_run_config_id"],
63+
["id"],
64+
)
65+
# ### end Alembic commands ###

app/api/api_v1/api.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
projects,
2222
test_collections,
2323
test_harness_backend_version,
24-
test_run_configs,
2524
test_run_executions,
2625
utils,
2726
)
@@ -39,9 +38,6 @@
3938
prefix="/test_run_executions",
4039
tags=["test_run_executions"],
4140
)
42-
api_router.include_router(
43-
test_run_configs.router, prefix="/test_run_configs", tags=["test_run_configs"]
44-
)
4541

4642
api_router.include_router(test_harness_backend_version.router, tags=["version"])
4743
api_router.include_router(utils.router, prefix="/utils", tags=["utils"])

app/api/api_v1/endpoints/test_run_configs.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

app/api/api_v1/endpoints/test_run_executions.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ def create_test_run_execution(
8282
"""
8383
Create new test run execution.
8484
"""
85-
test_run_execution_in.selected_tests = selected_tests
86-
test_run_execution = crud.test_run_execution.create(
87-
db=db, obj_in=test_run_execution_in
85+
test_run_execution = crud.test_run_execution.create_with_selected_tests(
86+
db=db, obj_in=test_run_execution_in, selected_tests=selected_tests
8887
)
8988
return test_run_execution
9089

@@ -259,13 +258,12 @@ def repeat_test_run_execution(
259258
test_run_execution_in.description = execution_to_repeat.description
260259
test_run_execution_in.project_id = execution_to_repeat.project_id
261260
test_run_execution_in.operator_id = execution_to_repeat.operator_id
262-
test_run_execution_in.selected_tests = selected_tests_from_execution(
263-
execution_to_repeat
264-
)
265-
# TODO: Remove test_run_config completely from the project
266-
test_run_execution_in.test_run_config_id = None
267261

268-
return crud.test_run_execution.create(db=db, obj_in=test_run_execution_in)
262+
return crud.test_run_execution.create_with_selected_tests(
263+
db=db,
264+
obj_in=test_run_execution_in,
265+
selected_tests=selected_tests_from_execution(execution_to_repeat),
266+
)
269267

270268

271269
@router.delete("/{id}", response_model=schemas.TestRunExecutionInDBBase)

app/crud/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .crud_project import project
1919
from .crud_test_case_execution import test_case_execution
2020
from .crud_test_case_metadata import test_case_metadata
21-
from .crud_test_run_config import test_run_config
2221
from .crud_test_run_execution import test_run_execution
2322
from .crud_test_step_execution import test_step_execution
2423
from .crud_test_suite_execution import test_suite_execution

app/crud/crud_test_run_config.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/crud/crud_test_run_execution.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222

2323
from app.crud import operator as crud_operator
2424
from app.crud import project as crud_project
25-
from app.crud import test_run_config as crud_test_run_config
2625
from app.crud.base import CRUDBaseCreate, CRUDBaseDelete, CRUDBaseRead
2726
from app.models import Project, TestCaseExecution, TestRunExecution, TestSuiteExecution
2827
from app.schemas import (
29-
TestRunConfigCreate,
28+
SelectedTests,
3029
TestRunExecutionToExport,
3130
TestRunExecutionToImport,
3231
)
@@ -176,9 +175,22 @@ def create(
176175

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

178+
db.commit()
179+
db.refresh(test_run_execution)
180+
return test_run_execution
181+
182+
def create_with_selected_tests(
183+
self,
184+
db: Session,
185+
obj_in: TestRunExecutionCreate,
186+
selected_tests: SelectedTests,
187+
**kwargs: Optional[dict],
188+
) -> TestRunExecution:
189+
test_run_execution = self.create(db, obj_in=obj_in, **kwargs)
190+
179191
test_suites = (
180192
test_script_manager.pending_test_suite_executions_for_selected_tests(
181-
obj_in.selected_tests
193+
selected_tests
182194
)
183195
)
184196

@@ -258,12 +270,6 @@ def import_execution(
258270
)
259271
imported_execution.operator_id = operator_id
260272

261-
if execution.test_run_config:
262-
test_run_config = crud_test_run_config.create(
263-
db=db, obj_in=TestRunConfigCreate(**execution.test_run_config.__dict__)
264-
)
265-
imported_execution.test_run_config_id = test_run_config.id
266-
267273
imported_model = TestRunExecution(**jsonable_encoder(imported_execution))
268274

269275
db.add(imported_model)

app/db/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from app.models.project import Project # noqa
2121
from app.models.test_case_execution import TestCaseExecution # noqa
2222
from app.models.test_case_metadata import TestCaseMetadata # noqa
23-
from app.models.test_run_config import TestRunConfig # noqa
2423
from app.models.test_run_execution import TestRunExecution # noqa
2524
from app.models.test_step_execution import TestStepExecution # noqa
2625
from app.models.test_suite_execution import TestSuiteExecution # noqa

app/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .test_case_execution import TestCaseExecution
1919
from .test_case_metadata import TestCaseMetadata
2020
from .test_enums import TestStateEnum
21-
from .test_run_config import TestRunConfig
2221
from .test_run_execution import TestRunExecution
2322
from .test_step_execution import TestStepExecution
2423
from .test_suite_execution import TestSuiteExecution

app/models/test_run_config.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)