-
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
57928cf
commit 8a3ff39
Showing
8 changed files
with
230 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
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,66 @@ | ||
from ..api import rule | ||
from ..api._endpoint import ApiEndpoint | ||
from ..entities._entity import NotFound | ||
from ..entities.commit import Commit, CommitSerializer | ||
|
||
|
||
class CommitListAPI(ApiEndpoint): | ||
serializer = CommitSerializer() | ||
|
||
def get(self): | ||
""" | ||
--- | ||
description: Get a list of commits. | ||
responses: | ||
"200": "CommitList" | ||
"401": "401" | ||
tags: | ||
- Commits | ||
""" | ||
commits = Commit.all(limit=500) | ||
return self.serializer.many.dump(commits) | ||
|
||
|
||
class CommitEntityAPI(ApiEndpoint): | ||
serializer = CommitSerializer() | ||
|
||
def _get(self, commit_id): | ||
try: | ||
commit = Commit.one(id=commit_id) | ||
except NotFound: | ||
self.abort_404_not_found() | ||
return commit | ||
|
||
def get(self, commit_id): | ||
""" | ||
--- | ||
description: Get a commit. | ||
responses: | ||
"200": "CommitEntity" | ||
"401": "401" | ||
"404": "404" | ||
parameters: | ||
- name: commit_id | ||
in: path | ||
schema: | ||
type: string | ||
tags: | ||
- Commits | ||
""" | ||
commit = self._get(commit_id) | ||
return self.serializer.one.dump(commit) | ||
|
||
|
||
commit_entity_view = CommitEntityAPI.as_view("commit") | ||
commit_list_view = CommitListAPI.as_view("commits") | ||
|
||
rule( | ||
"/commits/<commit_id>/", | ||
view_func=commit_entity_view, | ||
methods=["GET"], | ||
) | ||
rule( | ||
"/commits/", | ||
view_func=commit_list_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
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,40 @@ | ||
from ...api._examples import _api_commit_entity | ||
from ...tests.api import _asserts | ||
from ...tests.api import _fixtures | ||
|
||
|
||
def _expected_entity(commit): | ||
return _api_commit_entity(commit.id) | ||
|
||
|
||
def create_commit(): | ||
summary = _fixtures.create_benchmark_summary() | ||
return summary.run.commit | ||
|
||
|
||
class TestCommitGet(_asserts.GetEnforcer): | ||
url = "/api/commits/{}/" | ||
public = True | ||
|
||
def _create(self): | ||
return create_commit() | ||
|
||
def test_get_commit(self, client): | ||
self.authenticate(client) | ||
commit = self._create() | ||
response = client.get(f"/api/commits/{commit.id}/") | ||
self.assert_200_ok(response, _expected_entity(commit)) | ||
|
||
|
||
class TestCommitList(_asserts.ListEnforcer): | ||
url = "/api/commits/" | ||
public = True | ||
|
||
def _create(self): | ||
return create_commit() | ||
|
||
def test_commit_list(self, client): | ||
self.authenticate(client) | ||
commit = self._create() | ||
response = client.get("/api/commits/") | ||
self.assert_200_ok(response, contains=_expected_entity(commit)) |