-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
3 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from tornado.web import asynchronous | ||
from tornado.gen import coroutine | ||
|
||
from bothub.api.serializers.repository import RepositorySerializer | ||
|
||
from . import ApiHandler | ||
from ..utils import authorization_required | ||
|
||
|
||
class InfoHandler(ApiHandler): | ||
@asynchronous | ||
@coroutine | ||
@authorization_required | ||
def get(self): | ||
repository_authorization = self.repository_authorization() | ||
repository = repository_authorization.repository | ||
serializer = RepositorySerializer(repository) | ||
self.finish(serializer.data) |
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,52 @@ | ||
import json | ||
|
||
from tornado.testing import AsyncHTTPTestCase | ||
from django.test import TestCase | ||
from rest_framework import status | ||
|
||
from bothub.authentication.models import User | ||
from bothub.common.models import Repository | ||
from bothub.common.models import RepositoryAuthorization | ||
from bothub.common import languages | ||
|
||
|
||
class InfoHandlerTestCase(AsyncHTTPTestCase, TestCase): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.user = User.objects.create( | ||
email='fake@user.com', | ||
nickname='fake') | ||
|
||
self.repository = Repository.objects.create( | ||
owner=self.user, | ||
slug='test', | ||
name='Testing', | ||
language=languages.LANGUAGE_EN) | ||
self.authorization = RepositoryAuthorization.objects.create( | ||
user=self.user, | ||
repository=self.repository) | ||
|
||
def get_app(self): | ||
from bothub_nlp.server import make_app | ||
return make_app() | ||
|
||
def test_okay(self): | ||
response = self.fetch( | ||
'/info/', | ||
method='GET', | ||
headers={ | ||
'Authorization': 'Bearer {}'.format( | ||
self.authorization.uuid), | ||
}, | ||
) | ||
|
||
self.assertEqual( | ||
response.code, | ||
status.HTTP_200_OK) | ||
|
||
content_data = json.loads(response.body) | ||
|
||
self.assertEqual( | ||
content_data.get('uuid'), | ||
str(self.repository.uuid)) |