Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete reruns endpoint #182

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() == []
Loading