From 82fa7b03a40abfd9b70f3128d35fd8fa0d0fbeab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Sat, 23 Nov 2013 19:20:44 +0100 Subject: [PATCH] Enable users to override the client used in tests. Fixes #7, thanks nkvoll! --- test_elasticsearch/test_server/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test_elasticsearch/test_server/__init__.py b/test_elasticsearch/test_server/__init__.py index a54c326d..758f149e 100644 --- a/test_elasticsearch/test_server/__init__.py +++ b/test_elasticsearch/test_server/__init__.py @@ -30,12 +30,21 @@ server = None pidfile = tempfile.mktemp() def get_client(**kwargs): + # construct kwargs from the environment kw = {} if 'TEST_ES_CONNECTION' in os.environ: from elasticsearch import connection kw['connection_class'] = getattr(connection, os.environ['TEST_ES_CONNECTION']) + # update them with params kw.update(kwargs) - return Elasticsearch([os.environ['TEST_ES_SERVER']], **kw) + + # try and locate manual override in the local environment + try: + from test_elasticsearch.local import get_client as local_get_client + return local_get_client([os.environ['TEST_ES_SERVER']], **kw) + except ImportError: + # fallback to using vanilla client + return Elasticsearch([os.environ['TEST_ES_SERVER']], **kw) def setup():