Exemplo n.º 1
0
    def test__exception(self):
        model = webservice.SimpleDataModel("test")
        for method in [m for m in dir(model) if "_item" in m]:
            setattr(model, method, mock.Mock(side_effect=Exception()))

        resource_mgr = application.ResourceManager()
        app = application.ApiApplication(resource_mgr)

        collection_handler = webservice.CollectionHandler(r'/c', model)
        resource_mgr.register_handler(collection_handler)
        for method in ['GET', 'POST']:
            request = webob.Request.blank('/c',
                                          body='{}'.encode('utf-8'),
                                          method=method)
            response = app(request)
            self._check_base_exc_response(method, response, 500)

        element_handler = webservice.ElementHandler(r'/e', model)
        resource_mgr.register_handler(element_handler)
        for method in ['GET', 'PUT', 'PATCH', 'DELETE']:
            request = webob.Request.blank('/e',
                                          body='{}'.encode('utf-8'),
                                          method=method)
            response = app(request)
            self._check_base_exc_response(method, response, 500)

            # Tests that making a request to an invalid url returns 404.
            request = webob.Request.blank('/invalid',
                                          body='{}'.encode('utf-8'),
                                          method=method)
            response = app(request)
            self._check_base_exc_response(method, response, 404)
Exemplo n.º 2
0
    def test_data_model_exception(self):
        exc = webservice.DataModelException(1, "error1", [1, {'a': 'b'}], 409)
        model = webservice.SimpleDataModel("test")
        for method in [m for m in dir(model) if "_item" in m]:
            setattr(model, method, mock.Mock(side_effect=exc))

        resource_mgr = application.ResourceManager()
        app = application.ApiApplication(resource_mgr)

        collection_handler = webservice.CollectionHandler(r'/c', model)
        resource_mgr.register_handler(collection_handler)
        for method in ['GET', 'POST']:
            request = webob.Request.blank('/c',
                                          body='{}'.encode('utf-8'),
                                          method=method)
            response = app(request)
            self._check_data_model_exc_response(method, exc, response)

        element_handler = webservice.ElementHandler(r'/e', model)
        resource_mgr.register_handler(element_handler)
        for method in ['GET', 'PUT', 'PATCH', 'DELETE']:
            request = webob.Request.blank('/e',
                                          body='{}'.encode('utf-8'),
                                          method=method)
            response = app(request)
            self._check_data_model_exc_response(method, exc, response)
Exemplo n.º 3
0
def congress_app_factory(global_conf, **local_conf):
    # global_conf only accepts an iteratable value as its dict value
    flags_dict = json.loads(global_conf['flags'])
    services = harness.create2(
        node_id=global_conf['node_id'],
        bus_id=global_conf['bus_id'],
        policy_engine=flags_dict['policy_engine'],
        api=flags_dict['api'],
        datasources=flags_dict['datasources'])
    return application.ApiApplication(services['api_service'])
Exemplo n.º 4
0
def wsgi_app():

    mapper = paste.urlmap.URLMap()
    mapper['/'] = versions.Versions()

    api_resource_mgr = application.ResourceManager()
    api_resource_mgr.register_handler(versions.VersionV1Handler(r'/v1[/]?'))
    app = application.ApiApplication(api_resource_mgr)
    mapper['/v1'] = app

    return mapper
Exemplo n.º 5
0
def congress_app_factory(global_conf, **local_conf):
    root_path = cfg.CONF.root_path
    if root_path is None:
        root_path = os.path.dirname(__file__)   # drop filename
        root_path = os.path.dirname(root_path)  # drop to congress src dir
    policy_path = cfg.CONF.policy_path
    if policy_path is None:
        policy_path = os.path.join(root_path, 'etc', 'snapshot')
    data_path = cfg.CONF.datasource_file
    if data_path is None:
        data_path = os.path.join(root_path, 'etc', 'datasources.conf')

    cage = harness.create(root_path, policy_path, data_path)

    api_resource_mgr = application.ResourceManager()
    router.APIRouterV1(api_resource_mgr, cage)
    return application.ApiApplication(api_resource_mgr)