From e5b62db50e40efad8fd986ee156b54157c35d46b Mon Sep 17 00:00:00 2001 From: Omar Selo Date: Fri, 1 Dec 2023 12:19:20 +0000 Subject: [PATCH] Fix mypy issues --- backend/scripts/seed_data.py | 2 +- .../controllers/test_executions/models.py | 4 +++- .../test_executions/test_executions.py | 18 ++++++++++++++---- backend/test_observer/data_access/models.py | 4 ++-- .../test_executions/test_test_executions.py | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/backend/scripts/seed_data.py b/backend/scripts/seed_data.py index 7e37151e..07100cc6 100644 --- a/backend/scripts/seed_data.py +++ b/backend/scripts/seed_data.py @@ -120,7 +120,7 @@ def seed_data(client: TestClient | requests.Session): for request in REQUESTS: client.put( - START_TEST_EXECUTION_URL, data=request.model_dump_json() + START_TEST_EXECUTION_URL, json=request.model_dump(mode="json") ).raise_for_status() diff --git a/backend/test_observer/controllers/test_executions/models.py b/backend/test_observer/controllers/test_executions/models.py index e7f1acf2..12cfc555 100644 --- a/backend/test_observer/controllers/test_executions/models.py +++ b/backend/test_observer/controllers/test_executions/models.py @@ -18,6 +18,8 @@ # Omar Selo +from typing import Annotated + from pydantic import BaseModel, HttpUrl, field_serializer, model_validator from test_observer.data_access.models_enums import FamilyName, TestExecutionStatus @@ -35,7 +37,7 @@ class StartTestExecutionRequest(BaseModel): arch: str execution_stage: str environment: str - ci_link: HttpUrl + ci_link: Annotated[str, HttpUrl] @field_serializer("family") def serialize_dt(self, family: FamilyName): diff --git a/backend/test_observer/controllers/test_executions/test_executions.py b/backend/test_observer/controllers/test_executions/test_executions.py index 509c6191..d56c2306 100644 --- a/backend/test_observer/controllers/test_executions/test_executions.py +++ b/backend/test_observer/controllers/test_executions/test_executions.py @@ -105,8 +105,18 @@ def patch_test_execution( request: TestExecutionsPatchRequest, db: Session = Depends(get_db), ): - test_execution = db.query(TestExecution).filter(TestExecution.id == id).one() - test_execution.c3_link = request.c3_link - test_execution.ci_link = request.ci_link - test_execution.status = request.status + test_execution = db.get(TestExecution, id) + + if test_execution is None: + raise HTTPException(status_code=404, detail="TestExecution not found") + + if request.c3_link is not None: + test_execution.c3_link = str(request.c3_link) + + if request.ci_link is not None: + test_execution.ci_link = str(request.ci_link) + + if request.status is not None: + test_execution.status = request.status + db.commit() diff --git a/backend/test_observer/data_access/models.py b/backend/test_observer/data_access/models.py index ec736bee..5d515359 100644 --- a/backend/test_observer/data_access/models.py +++ b/backend/test_observer/data_access/models.py @@ -198,8 +198,8 @@ class TestExecution(Base): __tablename__ = "test_execution" - ci_link: Mapped[str] = mapped_column(String(200), nullable=True) - c3_link: Mapped[str] = mapped_column(String(200), nullable=True) + ci_link: Mapped[str | None] = mapped_column(String(200), nullable=True) + c3_link: Mapped[str | None] = mapped_column(String(200), nullable=True) # Relationships artefact_build_id: Mapped[int] = mapped_column( ForeignKey("artefact_build.id", ondelete="CASCADE") diff --git a/backend/tests/controllers/test_executions/test_test_executions.py b/backend/tests/controllers/test_executions/test_test_executions.py index 01f393f3..b3fc7c35 100644 --- a/backend/tests/controllers/test_executions/test_test_executions.py +++ b/backend/tests/controllers/test_executions/test_test_executions.py @@ -154,7 +154,7 @@ def test_uses_existing_models(db_session: Session, test_client: TestClient): test_execution_id = test_client.put( "/v1/test-executions/start-test", - data=request.model_dump_json(), + json=request.model_dump(mode="json"), ).json()["id"] test_execution = (