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)
def test_dispatch_route_bad_request(self): controller = StubController() request = Spy() result = yield controller.render(request) self.assertIsInstance(result, response.BadRequest)
def test_dispatch_route_not_found(self): controller = StubController() request = DummyRequest(['/unknown']) result = yield controller.render(request) self.assertIsInstance(result, response.NotFound)
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)
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')
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))
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)
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)