Skip to content

Commit

Permalink
Add info handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dougppaz committed Jun 27, 2018
1 parent decec3b commit 898146e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bothub_nlp/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .. import settings
from .handlers.parse import ParseHandler
from .handlers.train import TrainHandler
from .handlers.info import InfoHandler


logging.basicConfig(format=settings.LOGGER_FORMAT)
Expand All @@ -17,4 +18,5 @@ def make_app():
url('/', ParseHandler),
url('/parse/', ParseHandler),
url('/train/', TrainHandler),
url('/info/', InfoHandler),
])
18 changes: 18 additions & 0 deletions bothub_nlp/server/handlers/info.py
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)
52 changes: 52 additions & 0 deletions bothub_nlp/server/handlers/tests/test_info_handler.py
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))

0 comments on commit 898146e

Please sign in to comment.