示例#1
0
    def test_client_configuration(self, settings, patched_client, key, value,
                                  settingkey):
        settings[settingkey] = value
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert kwargs[key] == value
示例#2
0
    def test_ignores_aws_auth_when_settings_missing(self, settings,
                                                    patched_client,
                                                    aws_settings):
        settings.update(aws_settings)
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert 'auth' not in kwargs
示例#3
0
    def test_client_configuration(
        self, settings, patched_client, key, value, settingkey
    ):
        settings[settingkey] = value
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert kwargs[key] == value
示例#4
0
    def test_initialises_aws_auth(self, settings, patched_aws_auth):
        settings.update({
            'es.aws.access_key_id': 'foo',
            'es.aws.secret_access_key': 'bar',
            'es.aws.region': 'baz'
        })
        get_client(settings)

        patched_aws_auth.assert_called_once_with('foo', 'bar', 'baz', 'es')
示例#5
0
    def test_sets_aws_auth(self, settings, patched_client, patched_aws_auth):
        settings.update({
            'es.aws.access_key_id': 'foo',
            'es.aws.secret_access_key': 'bar',
            'es.aws.region': 'baz'
        })
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert kwargs['http_auth'] == patched_aws_auth.return_value
示例#6
0
文件: client_test.py 项目: welhefna/h
    def test_sets_connection_class_for_aws_auth(self, settings,
                                                patched_client):
        settings.update({
            'es.aws.access_key_id': 'foo',
            'es.aws.secret_access_key': 'bar',
            'es.aws.region': 'baz'
        })
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert kwargs['connection_class'] == RequestsHttpConnection
示例#7
0
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'hypothesis')

    # Allow users of this module to register additional search filter and
    # search matcher factories.
    config.registry[FILTERS_KEY] = []
    config.registry[MATCHERS_KEY] = []
    config.add_directive(
        'add_search_filter',
        lambda c, f: c.registry[FILTERS_KEY].append(config.maybe_dotted(f)))
    config.add_directive('get_search_filters',
                         lambda c: c.registry[FILTERS_KEY])
    config.add_directive(
        'add_search_matcher',
        lambda c, m: c.registry[MATCHERS_KEY].append(config.maybe_dotted(m)))
    config.add_directive('get_search_matchers',
                         lambda c: c.registry[MATCHERS_KEY])

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry['es.client'] = get_client(settings)
    config.add_request_method(lambda r: r.registry['es.client'],
                              name='es',
                              reify=True)
示例#8
0
文件: __init__.py 项目: gnott/h
def includeme(config):
    settings = config.registry.settings
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'hypothesis')

    # Allow users of this module to register additional search filter and
    # search matcher factories.
    config.registry[FILTERS_KEY] = []
    config.registry[MATCHERS_KEY] = []
    config.add_directive('add_search_filter',
                         lambda c, f: c.registry[FILTERS_KEY].append(config.maybe_dotted(f)))
    config.add_directive('get_search_filters',
                         lambda c: c.registry[FILTERS_KEY])
    config.add_directive('add_search_matcher',
                         lambda c, m: c.registry[MATCHERS_KEY].append(config.maybe_dotted(m)))
    config.add_directive('get_search_matchers',
                         lambda c: c.registry[MATCHERS_KEY])

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry['es.client'] = get_client(settings)
    config.add_request_method(
        lambda r: r.registry['es.client'],
        name='es',
        reify=True)
示例#9
0
def includeme(config):
    settings = config.registry.settings

    # Connection to version 6.x of ES follows
    # TODO The munging of these settings may change when settings refactoring complete
    kwargs = {}
    kwargs['max_retries'] = settings.get('es.client.max_retries', 3)
    kwargs['retry_on_timeout'] = settings.get('es.client.retry_on_timeout', False)
    kwargs['timeout'] = settings.get('es.client.timeout', 10)

    if 'es.client_poolsize' in settings:
        kwargs['maxsize'] = settings['es.client_poolsize']

    connect(hosts=[settings['es.url']], **kwargs)

    # Connection to old (ES1.5) follows
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'hypothesis')

    # Add a property to all requests for easy access to the elasticsearch
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry['es.client'] = get_client(settings)
    config.add_request_method(
        lambda r: r.registry['es.client'],
        name='es',
        reify=True)
示例#10
0
    def test_it(self, Client, Elasticsearch, settings, expected):
        client = get_client(
            {"es.url": sentinel.url, "es.index": sentinel.index, **settings}
        )

        args, kwargs = Elasticsearch.call_args
        assert args, kwargs == (([sentinel.url],), Any.dict.containing(expected))

        Client.assert_called_once_with(
            index=sentinel.index, conn=Elasticsearch.return_value
        )
        assert client == Client.return_value
示例#11
0
文件: __init__.py 项目: kael/h
def includeme(config):
    settings = config.registry.settings

    kwargs = {}
    kwargs['max_retries'] = settings.get('es.client.max_retries', 3)
    kwargs['retry_on_timeout'] = settings.get('es.client.retry_on_timeout',
                                              False)
    kwargs['timeout'] = settings.get('es.client.timeout', 10)

    if 'es.client_poolsize' in settings:
        kwargs['maxsize'] = settings['es.client_poolsize']

    settings.setdefault('es.index', 'hypothesis')

    # Add a property to all requests for easy access to the elasticsearch 6.x
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry['es.client'] = get_client(settings)
    config.add_request_method(lambda r: r.registry['es.client'],
                              name='es',
                              reify=True)
def includeme(config):
    settings = config.registry.settings

    kwargs = {}
    kwargs["max_retries"] = settings.get("es.client.max_retries", 3)
    kwargs["retry_on_timeout"] = settings.get("es.client.retry_on_timeout",
                                              False)
    kwargs["timeout"] = settings.get("es.client.timeout", 10)

    if "es.client_poolsize" in settings:
        kwargs["maxsize"] = settings["es.client_poolsize"]

    settings.setdefault("es.index", "hypothesis")

    # Add a property to all requests for easy access to the elasticsearch 6.x
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry["es.client"] = get_client(settings)
    config.add_request_method(lambda r: r.registry["es.client"],
                              name="es",
                              reify=True)
示例#13
0
def includeme(config):
    settings = config.registry.settings

    # Connection to version 6.x of ES follows
    # TODO The munging of these settings may change when settings refactoring complete
    kwargs = {}
    kwargs['max_retries'] = settings.get('es.client.max_retries', 3)
    kwargs['retry_on_timeout'] = settings.get('es.client.retry_on_timeout', False)
    kwargs['timeout'] = settings.get('es.client.timeout', 10)

    if 'es.client_poolsize' in settings:
        kwargs['maxsize'] = settings['es.client_poolsize']

    connect(hosts=[settings['es.url']], **kwargs)

    # Connection to old (ES1.5) follows
    settings.setdefault('es.host', 'http://localhost:9200')
    settings.setdefault('es.index', 'hypothesis')

    # Add a property to all requests for easy access to the elasticsearch 1.x
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry['es.client'] = get_client(settings)
    config.add_request_method(
        lambda r: r.registry['es.client'],
        name='es',
        reify=True)

    # Add a property to all requests for easy access to the elasticsearch 6.x
    # client. This can be used for direct or bulk access without having to
    # reread the settings.
    config.registry['es6.client'] = get_es6_client(settings)
    config.add_request_method(
        lambda r: r.registry['es6.client'],
        name='es6',
        reify=True)
示例#14
0
 def test_initializes_client_with_host(self, settings, patched_client):
     get_client(settings)
     args, _ = patched_client.call_args
     assert args[0] == "search.svc"
示例#15
0
文件: client_test.py 项目: gnott/h
    def test_initialises_aws_auth(self, settings, patched_aws_auth):
        settings.update({'es.aws.access_key_id': 'foo', 'es.aws.secret_access_key': 'bar', 'es.aws.region': 'baz'})
        get_client(settings)

        patched_aws_auth.assert_called_once_with('foo', 'bar', 'baz', 'es')
示例#16
0
 def test_initializes_client_with_index(self, settings, patched_client):
     get_client(settings)
     args, _ = patched_client.call_args
     assert args[1] == "my-index"
示例#17
0
 def test_initializes_client_with_host(self, settings, patched_client):
     get_client(settings)
     args, _ = patched_client.call_args
     assert args[0] == "search.svc"
示例#18
0
文件: client_test.py 项目: gnott/h
    def test_sets_aws_auth(self, settings, patched_client, patched_aws_auth):
        settings.update({'es.aws.access_key_id': 'foo', 'es.aws.secret_access_key': 'bar', 'es.aws.region': 'baz'})
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert kwargs['http_auth'] == patched_aws_auth.return_value
示例#19
0
文件: client_test.py 项目: gnott/h
    def test_sets_connection_class_for_aws_auth(self, settings, patched_client):
        settings.update({'es.aws.access_key_id': 'foo', 'es.aws.secret_access_key': 'bar', 'es.aws.region': 'baz'})
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert kwargs['connection_class'] == RequestsHttpConnection
示例#20
0
文件: client_test.py 项目: gnott/h
    def test_ignores_aws_auth_when_settings_missing(self, settings, patched_client, aws_settings):
        settings.update(aws_settings)
        get_client(settings)

        _, kwargs = patched_client.call_args
        assert 'auth' not in kwargs
示例#21
0
 def test_initializes_client_with_index(self, settings, patched_client):
     get_client(settings)
     args, _ = patched_client.call_args
     assert args[1] == "my-index"