Beispiel #1
0
class StubController(object):

    def __init__(self):
        self.path = ''
        self._router = Router()
        self._router.install_routes(self)
        self.children = {}

    def render(self, request):
        return self._router.dispatch(self, request)

    def get_register_path(self):
        return self.path

    @decoroute('/test/<int:user_id>')
    def test(self, request, user_id, **kwargs):
        return 'User ID : {}'.format(user_id)

    @decoroute('/defer')
    @defer.inlineCallbacks
    def deferred(self, request, **kwargs):
        val1 = yield 'Hello '
        val2 = yield 'Defer!'
        defer.returnValue(val1 + val2)

    @decoroute('/209')
    def unknown(self, request, **kwargs):
        pass
Beispiel #2
0
class StubController(object):
    def __init__(self):
        self.path = ''
        self._router = Router()
        self._router.install_routes(self)

    def render(self, request):
        return self._router.dispatch(self, request)

    def get_register_path(self):
        return self.path

    @decoroute('/test/<int:user_id>')
    def test(self, request, user_id, **kwargs):
        return 'User ID : {}'.format(user_id)

    @decoroute('/defer')
    @defer.inlineCallbacks
    def deferred(self, request, **kwargs):
        val1 = yield 'Hello '
        val2 = yield 'Defer!'
        defer.returnValue(val1 + val2)

    @decoroute('/209')
    def unknown(self, request, **kwargs):
        pass
Beispiel #3
0
    def test_dispatch_returns_unknown_209_on_no_return_from_method(self):

        controller = StubController()
        request = request_generator(['/209'], method='GET')
        router = Router()
        router.install_routes(controller)

        self.assertIsInstance(
            router.dispatch(controller, request).result, response.Unknown)
Beispiel #4
0
    def test_dispatch_returns_unknown_209_on_no_return_from_method(self):

        controller = StubController()
        request = request_generator(['/209'], method='GET')
        router = Router()
        router.install_routes(controller)

        self.assertIsInstance(
            router.dispatch(controller, request).result, response.Unknown
        )