示例#1
0
def create_resource():
    """Search resource factory method"""
    plugins = utils.get_search_plugins()
    policy_enforcer = policy.Enforcer()
    deserializer = RequestDeserializer(plugins,
                                       policy_enforcer=policy_enforcer)
    serializer = ResponseSerializer()
    controller = SearchController(plugins, policy_enforcer=policy_enforcer)
    return wsgi.Resource(controller, deserializer, serializer)
示例#2
0
    def test_resource_call_error_handle_localized(self,
                                                  mock_translate_exception):
        class Controller(object):
            def delete(self, req, identity):
                raise webob.exc.HTTPBadRequest(explanation='Not Found')

        actions = {'action': 'delete', 'identity': 12}
        env = {'wsgiorg.routing_args': [None, actions]}
        request = wsgi.Request.blank('/tests/123', environ=env)
        message_es = 'No Encontrado'

        resource = wsgi.Resource(Controller(), wsgi.JSONRequestDeserializer(),
                                 None)
        translated_exc = webob.exc.HTTPBadRequest(message_es)
        mock_translate_exception.return_value = translated_exc

        e = self.assertRaises(webob.exc.HTTPBadRequest, resource, request)
        self.assertEqual(message_es, str(e))
示例#3
0
    def __init__(self, mapper):

        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        search_catalog_resource = search.create_resource()
        mapper.connect('/search',
                       controller=search_catalog_resource,
                       action='search',
                       conditions={'method': ['GET']})
        mapper.connect('/search',
                       controller=search_catalog_resource,
                       action='search',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/search',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/search/plugins',
                       controller=search_catalog_resource,
                       action='plugins_info',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/search/plugins',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/search/facets',
                       controller=search_catalog_resource,
                       action='facets',
                       conditions={'method': ['GET']}),
        mapper.connect(
            '/search/facets',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        super(API, self).__init__(mapper)
示例#4
0
def create_resource(conf):
    return wsgi.Resource(Controller())