Skip to content

Commit

Permalink
Fix test execution incorrect status (#79)
Browse files Browse the repository at this point in the history
* Add more seed data including tests that ended

* Fix bug incorrectly setting failed test execution

* Add validation for version field

* Resolve type linting issue
  • Loading branch information
omar-selo authored Dec 12, 2023
1 parent ebf80b7 commit 8d7ca39
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 6 deletions.
134 changes: 130 additions & 4 deletions backend/scripts/seed_data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import requests
from fastapi.testclient import TestClient

from test_observer.controllers.test_executions.models import StartTestExecutionRequest
from test_observer.controllers.test_executions.models import (
C3TestResult,
C3TestResultStatus,
EndTestExecutionRequest,
StartTestExecutionRequest,
)
from test_observer.data_access.models_enums import FamilyName

BASE_URL = "http://localhost:30000/v1"
START_TEST_EXECUTION_URL = f"{BASE_URL}/test-executions/start-test"
END_TEST_EXECUTION_URL = f"{BASE_URL}/test-executions/end-test"

REQUESTS = [
START_REQUESTS = [
StartTestExecutionRequest(
family=FamilyName.SNAP,
name="core22",
Expand All @@ -20,6 +26,42 @@
environment="rpi2",
ci_link="http://example1",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
name="core22",
version="20230531",
revision=1,
track="22",
store="ubuntu",
arch="armhf",
execution_stage="beta",
environment="rpi4",
ci_link="http://example10",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
name="core22",
version="20230531",
revision=1,
track="22",
store="ubuntu",
arch="armhf",
execution_stage="beta",
environment="rpi3aplus",
ci_link="http://example11",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
name="core22",
version="20230531",
revision=1,
track="22",
store="ubuntu",
arch="armhf",
execution_stage="beta",
environment="rp3bplus",
ci_link="http://example12",
),
StartTestExecutionRequest(
family=FamilyName.SNAP,
name="docker",
Expand Down Expand Up @@ -116,11 +158,95 @@
),
]

END_REQUESTS = [
EndTestExecutionRequest(
id=1,
ci_link="http://example1",
test_results=[
C3TestResult(
id=1,
name="test1",
status=C3TestResultStatus.FAIL,
category="",
comment="",
io_log="",
),
C3TestResult(
id=2,
name="test2",
status=C3TestResultStatus.PASS,
category="",
comment="",
io_log="",
),
C3TestResult(
id=3,
name="test3",
status=C3TestResultStatus.SKIP,
category="",
comment="",
io_log="",
),
C3TestResult(
id=4,
name="test4",
status=C3TestResultStatus.FAIL,
category="",
comment="",
io_log="",
),
C3TestResult(
id=5,
name="test5",
status=C3TestResultStatus.PASS,
category="",
comment="",
io_log="",
),
C3TestResult(
id=6,
name="test6",
status=C3TestResultStatus.SKIP,
category="",
comment="",
io_log="",
),
],
),
EndTestExecutionRequest(
id=2,
ci_link="http://example2",
test_results=[
C3TestResult(
id=7,
name="test7",
status=C3TestResultStatus.PASS,
category="",
comment="",
io_log="",
),
C3TestResult(
id=8,
name="test8",
status=C3TestResultStatus.SKIP,
category="",
comment="",
io_log="",
),
],
),
]


def seed_data(client: TestClient | requests.Session):
for request in REQUESTS:
for start_request in START_REQUESTS:
client.put(
START_TEST_EXECUTION_URL, json=start_request.model_dump(mode="json")
).raise_for_status()

for end_request in END_REQUESTS:
client.put(
START_TEST_EXECUTION_URL, json=request.model_dump(mode="json")
END_TEST_EXECUTION_URL, json=end_request.model_dump(mode="json")
).raise_for_status()


Expand Down
2 changes: 1 addition & 1 deletion backend/test_observer/controllers/test_executions/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def compute_test_execution_status(
test_results: list[TestResult],
) -> TestExecutionStatus:
failed = any(r.status == C3TestResultStatus.FAIL for r in test_results)
failed = any(r.status == TestResultStatus.FAILED for r in test_results)
status = TestExecutionStatus.FAILED if failed else TestExecutionStatus.PASSED
return status

Expand Down
15 changes: 14 additions & 1 deletion backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
from enum import Enum
from typing import Annotated

from pydantic import BaseModel, HttpUrl, field_serializer, model_validator
from pydantic import (
BaseModel,
HttpUrl,
field_serializer,
field_validator,
model_validator,
)

from test_observer.data_access.models_enums import FamilyName, TestExecutionStatus

Expand All @@ -44,6 +50,13 @@ class StartTestExecutionRequest(BaseModel):
def serialize_dt(self, family: FamilyName):
return family.value

@field_validator("version")
@classmethod
def validate_version(cls: type["StartTestExecutionRequest"], version: str) -> str:
if version in ("", "null"):
raise ValueError(f"Invalid version value '{version}'")
return version

@model_validator(mode="after")
def validate_required_fields(self) -> "StartTestExecutionRequest":
required_fields = {
Expand Down

0 comments on commit 8d7ca39

Please sign in to comment.