Example #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
Example #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
Example #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
Example #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')
Example #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
Example #6
0
    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
Example #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)
Example #8
0
File: __init__.py Project: 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)
Example #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)
Example #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
Example #11
0
File: __init__.py Project: 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)
Example #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)
Example #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"
Example #15
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')
Example #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"
Example #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"
Example #18
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
Example #19
0
    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
Example #20
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
Example #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"