From 6761d8230d59031ad5183615f68a71e51f5f0309 Mon Sep 17 00:00:00 2001 From: Matthew Breeden Date: Thu, 4 May 2017 17:05:46 -0700 Subject: [PATCH 1/2] Allow ignored params to Elasticsearch --- elasticmock/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elasticmock/__init__.py b/elasticmock/__init__.py index 0b92193..d4b52be 100644 --- a/elasticmock/__init__.py +++ b/elasticmock/__init__.py @@ -9,7 +9,7 @@ ELASTIC_INSTANCES = {} -def _get_elasticmock(hosts=None): +def _get_elasticmock(hosts=None, *args, **kwargs): elastic_key = 'localhost:9200' if hosts is None else '{0}:{1}'.format(hosts[0].get('host'), hosts[0].get('port')) if elastic_key in ELASTIC_INSTANCES: connection = ELASTIC_INSTANCES.get(elastic_key) From 59eb6eaf18c67c424dad35f82f6baac6c93de380 Mon Sep 17 00:00:00 2001 From: Matthew Breeden Date: Thu, 4 May 2017 17:15:18 -0700 Subject: [PATCH 2/2] Allow the same 'hosts' settings that Elasticsearch does --- elasticmock/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/elasticmock/__init__.py b/elasticmock/__init__.py index d4b52be..699587b 100644 --- a/elasticmock/__init__.py +++ b/elasticmock/__init__.py @@ -2,6 +2,7 @@ from functools import wraps +from elasticsearch.client import _normalize_hosts from mock import patch from elasticmock.fake_elasticsearch import FakeElasticsearch @@ -10,7 +11,11 @@ def _get_elasticmock(hosts=None, *args, **kwargs): - elastic_key = 'localhost:9200' if hosts is None else '{0}:{1}'.format(hosts[0].get('host'), hosts[0].get('port')) + host = _normalize_hosts(hosts)[0] + elastic_key = '{0}:{1}'.format( + host.get('host', 'localhost'), host.get('port', 9200) + ) + if elastic_key in ELASTIC_INSTANCES: connection = ELASTIC_INSTANCES.get(elastic_key) else: