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_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 #4
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 #5
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 #6
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(
        'memex_add_search_filter',
        lambda c, f: c.registry[FILTERS_KEY].append(config.maybe_dotted(f)))
    config.add_directive('memex_get_search_filters',
                         lambda c: c.registry[FILTERS_KEY])
    config.add_directive(
        'memex_add_search_matcher',
        lambda c, m: c.registry[MATCHERS_KEY].append(config.maybe_dotted(m)))
    config.add_directive('memex_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 #7
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 #8
0
 def test_initializes_client_with_host(self, settings, patched_client):
     get_client(settings)
     args, _ = patched_client.call_args
     assert args[0] == 'search.svc'