Skip to content

Commit

Permalink
Merge pull request #2 from mattbreeden/master
Browse files Browse the repository at this point in the history
Allow the same arguments to the mock that elasticsearch.Elasticsearch allows
  • Loading branch information
vrcmarcos committed May 7, 2017
2 parents d7dd667 + 59eb6ea commit cb311f7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions elasticmock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

from functools import wraps

from elasticsearch.client import _normalize_hosts
from mock import patch

from elasticmock.fake_elasticsearch import FakeElasticsearch

ELASTIC_INSTANCES = {}


def _get_elasticmock(hosts=None):
elastic_key = 'localhost:9200' if hosts is None else '{0}:{1}'.format(hosts[0].get('host'), hosts[0].get('port'))
def _get_elasticmock(hosts=None, *args, **kwargs):
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 cb311f7

Please sign in to comment.