Skip to content

Commit

Permalink
Add delete reruns endpoint (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed May 10, 2024
1 parent a48a351 commit ff38d48
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backend/test_observer/controllers/test_executions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ class PendingRerun(BaseModel):
"test_execution", "artefact_build", "artefact", "stage", "family", "name"
)
)


class DeleteReruns(BaseModel):
test_execution_ids: set[int]
13 changes: 11 additions & 2 deletions backend/test_observer/controllers/test_executions/reruns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy import select
from sqlalchemy import delete, select
from sqlalchemy.orm import Session, joinedload

from test_observer.data_access.models import (
Expand All @@ -12,7 +12,7 @@
from test_observer.data_access.repository import get_or_create
from test_observer.data_access.setup import get_db

from .models import PendingRerun, RerunRequest
from .models import DeleteReruns, PendingRerun, RerunRequest

router = APIRouter()

Expand All @@ -38,3 +38,12 @@ def get_rerun_requests(db: Session = Depends(get_db)):
.joinedload(Stage.family)
)
)


@router.delete("/reruns")
def delete_rerun_requests(request: DeleteReruns, db: Session = Depends(get_db)):
return db.execute(
delete(TestExecutionRerunRequest).where(
TestExecutionRerunRequest.test_execution_id.in_(request.test_execution_ids)
)
)
20 changes: 20 additions & 0 deletions backend/tests/controllers/test_executions/test_reruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ def get_helper() -> Response:
return get_helper


@pytest.fixture
def delete(test_client: TestClient):
def delete_helper(data: Any) -> Response: # noqa: ANN401
return test_client.request("DELETE", reruns_url, json=data)

return delete_helper


Post: TypeAlias = Callable[[Any], Response]
Get: TypeAlias = Callable[[], Response]
Delete: TypeAlias = Callable[[Any], Response]


def test_post_no_data_returns_422(post: Post):
Expand Down Expand Up @@ -106,3 +115,14 @@ def test_get_after_two_different_posts(
"family": te2.artefact_build.artefact.stage.family.name,
},
]


def test_post_delete_get(
get: Get, post: Post, delete: Delete, test_execution: TestExecution
):
test_execution.ci_link = "ci.link"
post({"test_execution_id": test_execution.id})
response = delete({"test_execution_ids": [test_execution.id]})

assert response.status_code == 200
assert get().json() == []

0 comments on commit ff38d48

Please sign in to comment.