Example #1
0
    def test_dispatch_route_not_implemented(self):

        controller = StubController()
        request = request_generator(['/test/102'], 'POST')

        result = yield controller.render(request)
        self.assertIsInstance(result, response.NotImplemented)
Example #2
0
    def test_dispatch_route_not_implemented(self):

        controller = StubController()
        request = request_generator(['/test/102'], 'POST')

        result = yield controller.render(request)
        self.assertIsInstance(result, response.NotImplemented)
Example #3
0
    def test_dispatch_route_bad_request(self):

        controller = StubController()
        request = Spy()

        result = yield controller.render(request)
        self.assertIsInstance(result, response.BadRequest)
Example #4
0
    def test_dispatch_route_not_found(self):

        controller = StubController()
        request = DummyRequest(['/unknown'])

        result = yield controller.render(request)
        self.assertIsInstance(result, response.NotFound)
Example #5
0
    def test_dispatch_route_bad_request(self):

        controller = StubController()
        request = Spy()

        result = yield controller.render(request)
        self.assertIsInstance(result, response.BadRequest)
Example #6
0
    def test_dispatch_route_not_found(self):

        controller = StubController()
        request = DummyRequest(['/unknown'])

        result = yield controller.render(request)
        self.assertIsInstance(result, response.NotFound)
Example #7
0
    def test_dispatch_route_internal_server_error(self):

        controller = StubController()
        request = request_generator(['/test/102'], headers=False)

        result = yield controller.render(request)
        self.assertIsInstance(result, response.InternalServerError)
        self.flushLoggedErrors(AttributeError)
Example #8
0
    def test_dispatch_route_internal_server_error(self):

        controller = StubController()
        request = request_generator(['/test/102'], headers=False)

        result = yield controller.render(request)
        self.assertIsInstance(result, response.InternalServerError)
        self.flushLoggedErrors(AttributeError)
Example #9
0
    def test_dispatch_route(self):

        controller = StubController()
        request = request_generator(['/test/102'])

        result = yield controller.render(request)
        self.assertIsInstance(result, response.Ok)
        self.assertEqual(result.subject, 'User ID : 102')
        self.assertEqual(result.headers.get('content-type'), 'text/plain')
Example #10
0
 def _render(self, controller, request):
     result = controller.render(request)
     if result is server.NOT_DONE_YET:
         if request.finished:
             return defer.succeed(request)
         else:
             return request.notifyFinish().addCallback(lambda _: request)
     else:
         raise ValueError('Unexpected return value: {}'.format(result))
Example #11
0
    def test_dispatch_route(self):

        controller = StubController()
        request = request_generator(['/test/102'])

        result = yield controller.render(request)
        self.assertIsInstance(result, response.Ok)
        self.assertEqual(result.subject, 'User ID : 102')
        self.assertEqual(result.headers.get('content-type'), 'text/plain')
Example #12
0
    def test_dispatch_route_adds_form_parameters_on_put_request(self):

        StubController.test2 = routes_generator('Test', method='PUT')
        request = request_generator(['/test2'], method='PUT')
        request.requestHeaders.setRawHeaders(
            'content-type', ['application/x-www-form-urlencoded'])
        request.content.write('name=test')
        request.content.seek(0, 0)
        controller = StubController()

        result = yield controller.render(request)
        self.assertIsInstance(result, response.Ok)
        self.assertTrue('name' in controller.test2.route.callback_args)
Example #13
0
    def test_dispatch_route_adds_form_parameters_on_put_request(self):

        StubController.test2 = routes_generator('Test', method='PUT')
        request = request_generator(['/test2'], method='PUT')
        request.requestHeaders.setRawHeaders(
            'content-type', ['application/x-www-form-urlencoded']
        )
        request.content.write('name=test')
        request.content.seek(0, 0)
        controller = StubController()

        result = yield controller.render(request)
        self.assertIsInstance(result, response.Ok)
        self.assertTrue('name' in controller.test2.route.callback_args)