Skip to content

Commit

Permalink
Add more information to pending rerun results
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbritton committed Jan 13, 2025
1 parent ea4eda0 commit 84665d2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 47 deletions.
9 changes: 8 additions & 1 deletion backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,19 @@ class RerunRequest(BaseModel):

class PendingRerun(BaseModel):
test_execution_id: int
ci_link: str = Field(validation_alias=AliasPath("test_execution", "ci_link"))
ci_link: str | None = Field(validation_alias=AliasPath("test_execution", "ci_link"))
family: FamilyName = Field(
validation_alias=AliasPath(
"test_execution", "artefact_build", "artefact", "family"
)
)
test_execution_status: TestExecutionStatus = Field(validation_alias=AliasPath("test_execution", "status"))
artefact_name: str = Field(validation_alias=AliasPath("test_execution", "artefact_build", "artefact", "name"))
version: str = Field(validation_alias=AliasPath("test_execution", "artefact_build", "artefact", "version"))
revision: int | None = Field(validation_alias=AliasPath("test_execution", "artefact_build", "revision"))
architecture: str = Field(validation_alias=AliasPath("test_execution", "environment", "architecture"))
environment: str = Field(validation_alias=AliasPath("test_execution", "environment", "name"))
test_plan: str = Field(validation_alias=AliasPath("test_execution", "test_plan"))


class DeleteReruns(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion backend/test_observer/controllers/test_executions/reruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def get_rerun_requests(db: Session = Depends(get_db)):
select(TestExecutionRerunRequest).options(
joinedload(TestExecutionRerunRequest.test_execution)
.joinedload(TestExecution.artefact_build)
.joinedload(ArtefactBuild.artefact)
.joinedload(ArtefactBuild.artefact),
joinedload(TestExecutionRerunRequest.test_execution)
.joinedload(TestExecution.environment)
)
)

Expand Down
64 changes: 19 additions & 45 deletions backend/tests/controllers/test_executions/test_reruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ def delete_helper(data: Any) -> Response: # noqa: ANN401
Get: TypeAlias = Callable[[], Response]
Delete: TypeAlias = Callable[[Any], Response]

def test_execution_to_pending_rerun(test_execution: TestExecution) -> dict:
return {
"test_execution_id": test_execution.id,
"ci_link": test_execution.ci_link,
"family": test_execution.artefact_build.artefact.family,
"test_execution_status": test_execution.status,
"artefact_name": test_execution.artefact_build.artefact.name,
"version": test_execution.artefact_build.artefact.version,
"revision": test_execution.artefact_build.revision,
"architecture": test_execution.environment.architecture,
"environment": test_execution.environment.name,
"test_plan": test_execution.test_plan,
}


def test_post_no_data_returns_422(post: Post):
assert post(None).status_code == 422
Expand All @@ -57,13 +71,7 @@ def test_valid_post(post: Post, test_execution: TestExecution):
response = post({"test_execution_ids": [test_execution.id]})

assert response.status_code == 200
assert response.json() == [
{
"test_execution_id": test_execution.id,
"ci_link": test_execution.ci_link,
"family": test_execution.artefact_build.artefact.family,
}
]
assert response.json() == [test_execution_to_pending_rerun(test_execution)]


def test_post_with_valid_and_invalid_ids(post: Post, test_execution: TestExecution):
Expand All @@ -83,13 +91,7 @@ def test_get_after_one_post(get: Get, post: Post, test_execution: TestExecution)

post({"test_execution_ids": [test_execution.id]})

assert get().json() == [
{
"test_execution_id": test_execution.id,
"ci_link": test_execution.ci_link,
"family": test_execution.artefact_build.artefact.family,
}
]
assert get().json() == [test_execution_to_pending_rerun(test_execution)]


def test_get_after_two_identical_posts(
Expand All @@ -100,13 +102,7 @@ def test_get_after_two_identical_posts(
post({"test_execution_ids": [test_execution.id]})
post({"test_execution_ids": [test_execution.id]})

assert get().json() == [
{
"test_execution_id": test_execution.id,
"ci_link": test_execution.ci_link,
"family": test_execution.artefact_build.artefact.family,
}
]
assert get().json() == [test_execution_to_pending_rerun(test_execution)]


def test_get_after_two_different_posts(
Expand All @@ -121,18 +117,7 @@ def test_get_after_two_different_posts(
post({"test_execution_ids": [te1.id]})
post({"test_execution_ids": [te2.id]})

assert get().json() == [
{
"test_execution_id": te1.id,
"ci_link": te1.ci_link,
"family": te1.artefact_build.artefact.family,
},
{
"test_execution_id": te2.id,
"ci_link": te2.ci_link,
"family": te2.artefact_build.artefact.family,
},
]
assert get().json() == [test_execution_to_pending_rerun(te1), test_execution_to_pending_rerun(te2)]


def test_get_after_post_with_two_test_execution_ids(
Expand All @@ -147,18 +132,7 @@ def test_get_after_post_with_two_test_execution_ids(

post({"test_execution_ids": [te1.id, te2.id]})

assert sorted(get().json(), key=itemgetter("test_execution_id")) == [
{
"test_execution_id": te1.id,
"ci_link": te1.ci_link,
"family": te1.artefact_build.artefact.family,
},
{
"test_execution_id": te2.id,
"ci_link": te2.ci_link,
"family": te2.artefact_build.artefact.family,
},
]
assert sorted(get().json(), key=itemgetter("test_execution_id")) == [test_execution_to_pending_rerun(te1), test_execution_to_pending_rerun(te2)]


def test_post_delete_get(
Expand Down

0 comments on commit 84665d2

Please sign in to comment.