Allow test client to be created with kwargs

This commit is contained in:
Honza Král
2016-07-12 18:02:46 +02:00
parent ef41d893aa
commit ac74778037
+10 -7
View File
@@ -2,20 +2,23 @@ from elasticsearch.helpers.test import get_test_client, ElasticsearchTestCase as
client = None client = None
def get_client(): def get_client(**kwargs):
global client global client
if client is not None: if client is not None and not kwargs:
return client return client
# try and locate manual override in the local environment # try and locate manual override in the local environment
try: try:
from test_elasticsearch.local import get_client as local_get_client from test_elasticsearch.local import get_client as local_get_client
client = local_get_client() new_client = local_get_client(**kwargs)
except ImportError: except ImportError:
# fallback to using vanilla client # fallback to using vanilla client
client = get_test_client() new_client = get_test_client(**kwargs)
return client if not kwargs:
client = new_client
return new_client
def setup(): def setup():
@@ -23,5 +26,5 @@ def setup():
class ElasticsearchTestCase(BaseTestCase): class ElasticsearchTestCase(BaseTestCase):
@staticmethod @staticmethod
def _get_client(): def _get_client(**kwargs):
return get_client() return get_client(**kwargs)