Skip to content

Commit

Permalink
Persist run info
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Mar 4, 2021
1 parent f719b6f commit 199a3b0
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 7 deletions.
1 change: 1 addition & 0 deletions conbench/api/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _201_created(example, schema=None):
spec.components.response("ContextEntity", _200_ok(ex.CONTEXT_ENTITY))
spec.components.response("MachineEntity", _200_ok(ex.MACHINE_ENTITY))
spec.components.response("RunEntity", _200_ok(ex.RUN_ENTITY))
spec.components.response("RunList", _200_ok(ex.RUN_LIST))
spec.components.response("UserEntity", _200_ok(ex.USER_ENTITY))
spec.components.response("UserList", _200_ok(ex.USER_LIST))
spec.components.response("UserCreated", _201_created(ex.USER_ENTITY))
Expand Down
5 changes: 5 additions & 0 deletions conbench/api/_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def _api_run_entity(run_id, machine_id):
CONTEXT_ENTITY = _api_context_entity("some-context-uuid-1")
MACHINE_ENTITY = _api_machine_entity("some-machine-uuid-1")
RUN_ENTITY = _api_run_entity("some-run-uuid-1", "some-machine-uuid-1")
RUN_LIST = [
_api_run_entity("some-run-uuid-1", "some-machine-uuid-1"),
_api_run_entity("some-run-uuid-2", "some-machine-uuid-1"),
]
USER_ENTITY = _api_user_entity(FakeUser1())
USER_LIST = [
_api_user_entity(FakeUser1()),
Expand Down Expand Up @@ -289,6 +293,7 @@ def _api_run_entity(run_id, machine_id):
"login": "http://localhost/api/login/",
"logout": "http://localhost/api/logout/",
"register": "http://localhost/api/register/",
"runs": "http://localhost/api/runs/",
"ping": "http://localhost/api/ping/",
"users": "http://localhost/api/users/",
}
Expand Down
7 changes: 4 additions & 3 deletions conbench/api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class IndexSerializer:
def dump(self):
return {
"links": {
"benchmarks": f.url_for("api.benchmarks", _external=True),
"docs": f.url_for("api.docs", _external=True),
"logout": f.url_for("api.logout", _external=True),
"login": f.url_for("api.login", _external=True),
"register": f.url_for("api.register", _external=True),
"logout": f.url_for("api.logout", _external=True),
"ping": f.url_for("api.ping", _external=True),
"register": f.url_for("api.register", _external=True),
"runs": f.url_for("api.runs", _external=True),
"users": f.url_for("api.users", _external=True),
"benchmarks": f.url_for("api.benchmarks", _external=True),
}
}

Expand Down
23 changes: 23 additions & 0 deletions conbench/api/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,31 @@ def get(self, run_id):
return self.serializer.one.dump(run)


class RunListAPI(ApiEndpoint):
serializer = RunSerializer()

def get(self):
"""
---
description: Get a list of runs.
responses:
"200": "RunList"
"401": "401"
tags:
- Runs
"""
runs = Run.all()
return self.serializer.many.dump(runs)


run_entity_view = RunEntityAPI.as_view("run")
run_list_view = RunListAPI.as_view("runs")

rule(
"/runs/",
view_func=run_list_view,
methods=["GET"],
)
rule(
"/runs/<run_id>/",
view_func=run_entity_view,
Expand Down
20 changes: 16 additions & 4 deletions conbench/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,22 @@ def post(self):
user_entity_view = UserEntityAPI.as_view("user")
user_list_view = UserListAPI.as_view("users")

rule("/users/", view_func=user_list_view, methods=["GET", "POST"])
rule("/users/<user_id>/", view_func=user_entity_view, methods=["GET", "DELETE", "PUT"])
rule(
"/users/",
view_func=user_list_view,
methods=["GET", "POST"],
)
rule(
"/users/<user_id>/",
view_func=user_entity_view,
methods=["GET", "DELETE", "PUT"],
)
rule(
"/register/",
view_func=RegisterAPI.as_view("register"),
methods=["POST"],
)

spec.components.schema("UserCreate", schema=UserSchema.create)
spec.components.schema("UserUpdate", schema=UserSchema.update)

rule("/register/", view_func=RegisterAPI.as_view("register"), methods=["POST"])
spec.components.schema("Register", schema=RegisterSchema)
34 changes: 34 additions & 0 deletions conbench/tests/api/_expected_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
"logout": "http://localhost/api/logout/",
"ping": "http://localhost/api/ping/",
"register": "http://localhost/api/register/",
"runs": "http://localhost/api/runs/",
"users": "http://localhost/api/users/",
}
}
Expand Down Expand Up @@ -468,6 +469,29 @@
},
"description": "OK",
},
"RunList": {
"content": {
"application/json": {
"example": [
{
"id": "some-run-uuid-1",
"links": {
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"self": "http://localhost/api/runs/some-run-uuid-1/",
},
},
{
"id": "some-run-uuid-2",
"links": {
"machine": "http://localhost/api/machines/some-machine-uuid-1/",
"self": "http://localhost/api/runs/some-run-uuid-2/",
},
},
]
}
},
"description": "OK",
},
"UserCreated": {
"content": {
"application/json": {
Expand Down Expand Up @@ -923,6 +947,16 @@
"tags": ["Authentication"],
}
},
"/api/runs/": {
"get": {
"description": "Get a list of runs.",
"responses": {
"200": {"$ref": "#/components/responses/RunList"},
"401": {"$ref": "#/components/responses/401"},
},
"tags": ["Runs"],
}
},
"/api/runs/{run_id}/": {
"get": {
"description": "Get a run.",
Expand Down
15 changes: 15 additions & 0 deletions conbench/tests/api/test_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ def test_get_run(self, client):
run = self._create()
response = client.get(f"/api/runs/{run.id}/")
self.assert_200_ok(response, _expected_entity(run))


class TestRunList(_asserts.ListEnforcer):
url = "/api/runs/"
public = True

def _create(self):
summary = create_benchmark_summary()
return summary.run

def test_benchmark_list(self, client):
self.authenticate(client)
run = self._create()
response = client.get("/api/runs/")
self.assert_200_ok(response, contains=_expected_entity(run))

0 comments on commit 199a3b0

Please sign in to comment.