Skip to content

Commit

Permalink
Adding api feature to support delete run executions
Browse files Browse the repository at this point in the history
  • Loading branch information
davisusanibar committed Sep 10, 2021
1 parent f8656a1 commit 41548a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
29 changes: 28 additions & 1 deletion conbench/api/runs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import flask_login

from ..api import rule
from ..api._endpoint import ApiEndpoint, maybe_login_required
from ..entities._entity import NotFound
from ..entities.run import Run, RunSerializer
from ..entities.summary import Summary


class RunEntityAPI(ApiEndpoint):
Expand Down Expand Up @@ -34,6 +37,30 @@ def get(self, run_id):
run = self._get(run_id)
return self.serializer.one.dump(run)

@flask_login.login_required
def delete(self, run_id):
"""
---
description: Delete a run.
responses:
"204": "204"
"401": "401"
"404": "404"
parameters:
- name: run_id
in: path
schema:
type: string
tags:
- Runs
"""
summaries = Summary.all(run_id=run_id)
for summarie in summaries:
summarie.delete()
run = self._get(run_id)
run.delete()
return self.response_204_no_content()


class RunListAPI(ApiEndpoint):
serializer = RunSerializer()
Expand Down Expand Up @@ -64,5 +91,5 @@ def get(self):
rule(
"/runs/<run_id>/",
view_func=run_entity_view,
methods=["GET"],
methods=["GET", "DELETE"],
)
19 changes: 18 additions & 1 deletion conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,23 @@
}
},
"/api/runs/{run_id}/": {
"delete": {
"description": "Delete a run.",
"parameters": [
{
"in": "path",
"name": "run_id",
"required": True,
"schema": {"type": "string"},
}
],
"responses": {
"204": {"$ref": "#/components/responses/204"},
"401": {"$ref": "#/components/responses/401"},
"404": {"$ref": "#/components/responses/404"},
},
"tags": ["Runs"],
},
"get": {
"description": "Get a run.",
"parameters": [
Expand All @@ -1277,7 +1294,7 @@
"404": {"$ref": "#/components/responses/404"},
},
"tags": ["Runs"],
}
},
},
"/api/users/": {
"get": {
Expand Down
12 changes: 12 additions & 0 deletions conbench/tests/api/test_runs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import urllib

from ...api._examples import _api_run_entity
from ...entities.summary import Summary
from ...tests.api import _asserts, _fixtures
from ...tests.helpers import _uuid

Expand Down Expand Up @@ -76,3 +77,14 @@ def test_run_list_filter_by_sha_and_machine_no_match(self, client):
args = urllib.parse.urlencode(args)
response = client.get(f"/api/runs/?{args}")
self.assert_200_ok(response, [])


class TestRunDelete(_asserts.DeleteEnforcer):
url = "api/runs/{}/"

def test_delete_run(self, client):
self.authenticate(client)
summary = _fixtures.create_benchmark_summary()
Summary.one(id=summary.id)
response = client.delete(f"/api/runs/{summary.run_id}/")
self.assert_204_no_content(response)

0 comments on commit 41548a5

Please sign in to comment.