-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42869d1
commit f719b6f
Showing
8 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ | |
from .contexts import * | ||
from .index import * | ||
from .machines import * | ||
from .runs import * | ||
from .users import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from ..api import rule | ||
from ..api._endpoint import ApiEndpoint | ||
from ..entities._entity import NotFound | ||
from ..entities.run import Run, RunSerializer | ||
|
||
|
||
class RunEntityAPI(ApiEndpoint): | ||
serializer = RunSerializer() | ||
|
||
def _get(self, run_id): | ||
try: | ||
run = Run.one(id=run_id) | ||
except NotFound: | ||
self.abort_404_not_found() | ||
return run | ||
|
||
def get(self, run_id): | ||
""" | ||
--- | ||
description: Get a run. | ||
responses: | ||
"200": "RunEntity" | ||
"401": "401" | ||
"404": "404" | ||
parameters: | ||
- name: run_id | ||
in: path | ||
schema: | ||
type: string | ||
tags: | ||
- Runs | ||
""" | ||
run = self._get(run_id) | ||
return self.serializer.one.dump(run) | ||
|
||
|
||
run_entity_view = RunEntityAPI.as_view("run") | ||
|
||
rule( | ||
"/runs/<run_id>/", | ||
view_func=run_entity_view, | ||
methods=["GET"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
import flask as f | ||
import sqlalchemy as s | ||
from sqlalchemy.orm import relationship | ||
|
||
from ..entities._entity import Base, EntityMixin, NotNull | ||
from ..entities._entity import Base, EntityMixin, EntitySerializer, NotNull | ||
|
||
|
||
class Run(Base, EntityMixin): | ||
__tablename__ = "run" | ||
id = NotNull(s.String(50), primary_key=True) | ||
timestamp = NotNull(s.DateTime(timezone=False), server_default=s.sql.func.now()) | ||
github_id = NotNull(s.String(50), s.ForeignKey("github.id")) | ||
github = relationship("GitHub", lazy="joined") | ||
github = relationship("GitHub", lazy="select") | ||
machine_id = NotNull(s.String(50), s.ForeignKey("machine.id")) | ||
machine = relationship("Machine", lazy="select") | ||
|
||
|
||
class _Serializer(EntitySerializer): | ||
def _dump(self, run): | ||
result = { | ||
"id": run.id, | ||
"links": { | ||
"self": f.url_for("api.run", run_id=run.id, _external=True), | ||
"machine": f.url_for( | ||
"api.machine", machine_id=run.machine_id, _external=True | ||
), | ||
}, | ||
} | ||
return result | ||
|
||
|
||
class RunSerializer: | ||
one = _Serializer() | ||
many = _Serializer(many=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import copy | ||
|
||
from ...api._examples import _api_run_entity | ||
from ...entities.summary import Summary | ||
from ...tests.api import _asserts | ||
from ...tests.api.test_benchmarks import VALID_PAYLOAD | ||
|
||
|
||
def _expected_entity(run): | ||
return _api_run_entity(run.id, run.machine_id) | ||
|
||
|
||
def create_benchmark_summary(): | ||
data = copy.deepcopy(VALID_PAYLOAD) | ||
summary = Summary.create(data) | ||
return summary | ||
|
||
|
||
class TestRunGet(_asserts.GetEnforcer): | ||
url = "/api/runs/{}/" | ||
public = True | ||
|
||
def _create(self): | ||
summary = create_benchmark_summary() | ||
return summary.run | ||
|
||
def test_get_run(self, client): | ||
self.authenticate(client) | ||
run = self._create() | ||
response = client.get(f"/api/runs/{run.id}/") | ||
self.assert_200_ok(response, _expected_entity(run)) |