Skip to content

Commit

Permalink
Allow the same 'hosts' settings that Elasticsearch does
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Breeden committed May 5, 2017
1 parent 6761d82 commit 59eb6ea
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion elasticmock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from functools import wraps

from elasticsearch.client import _normalize_hosts
from mock import patch

from elasticmock.fake_elasticsearch import FakeElasticsearch
Expand All @@ -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:
Expand Down

0 comments on commit 59eb6ea

Please sign in to comment.