def test_resource_call_exceptions(self): self.resource = wsgi.Resource(None) self.resource.deserialize_request = mock.Mock() self.resource.deserialize_request.side_effect = ( exceptions.UnsupportedContentType ) mock_request = mock.Mock() mock_request.headers = {} result = self.resource(mock_request) self.assertEqual(415, result.status_code) self.resource.deserialize_request.side_effect = ( exceptions.MalformedRequestBody ) result = self.resource(mock_request) self.assertEqual(400, result.status_code) self.resource.deserialize_request.side_effect = None self.resource.deserialize_request.return_value = ["", {"k": "v"}, ""] self.resource.execute_action = mock.Mock() self.resource.serialize_response = mock.Mock() self.resource.serialize_response.side_effect = Exception result = self.resource(mock_request) self.assertIsNotNone(result)
def test_get_action_args(self): self.resource = wsgi.Resource(None) result = self.resource.get_action_args(None) self.assertEqual({}, result) request_environment = {'wsgiorg.routing_args': ["arg_0", {"k": "v"}]} result = self.resource.get_action_args(request_environment) self.assertEqual({"k": "v"}, result)
def test_dispatch_except_attribute_error(self): mock_obj = mock.Mock(spec=wsgi.Resource) setattr(mock_obj, 'default', mock.Mock(return_value=mock.sentinel.ret_value)) resource = wsgi.Resource(None) result = resource.dispatch(mock_obj, 'invalid_action') self.assertEqual(mock.sentinel.ret_value, result) mock_obj.default.assert_called_once_with()
def create_resource(): specific_content_types = { 'get_ui': ['text/plain'], 'download': ['application/octet-stream'], 'get_logo': ['application/octet-stream'], 'get_supplier_logo': ['application/octet-stream'] } deserializer = wsgi.RequestDeserializer( specific_content_types=specific_content_types) return wsgi.Resource(Controller(), deserializer=deserializer)
def create_resource(): return wsgi.Resource(Controller())
def create_resource(): return wsgi.Resource(Controller(), serializer=wsgi.ServiceBrokerResponseSerializer())
def create_resource(): serializer = PackageSerializer() return wsgi.Resource(Controller(), serializer=serializer)