Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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()
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def create_resource():
    return wsgi.Resource(Controller())
Ejemplo n.º 6
0
def create_resource():
    return wsgi.Resource(Controller(),
                         serializer=wsgi.ServiceBrokerResponseSerializer())
Ejemplo n.º 7
0
def create_resource():
    serializer = PackageSerializer()
    return wsgi.Resource(Controller(), serializer=serializer)