2020-04-23 11:22:08 -05:00
|
|
|
# Licensed to Elasticsearch B.V under one or more agreements.
|
|
|
|
|
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
|
|
|
|
# See the LICENSE file in the project root for more information
|
|
|
|
|
|
2020-03-10 12:08:03 -05:00
|
|
|
from unittest import SkipTest
|
2020-01-19 00:02:02 +00:00
|
|
|
from elasticsearch.helpers import test
|
|
|
|
|
from elasticsearch.helpers.test import ElasticsearchTestCase as BaseTestCase
|
2013-05-27 23:02:38 +02:00
|
|
|
|
2014-01-18 21:08:15 +01:00
|
|
|
client = None
|
2013-05-27 23:02:38 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
|
2016-07-12 18:02:46 +02:00
|
|
|
def get_client(**kwargs):
|
2014-01-18 21:08:15 +01:00
|
|
|
global client
|
2020-03-10 12:08:03 -05:00
|
|
|
if client is False:
|
|
|
|
|
raise SkipTest("No client is available")
|
2016-07-12 18:02:46 +02:00
|
|
|
if client is not None and not kwargs:
|
2014-01-18 21:08:15 +01:00
|
|
|
return client
|
2013-05-27 23:02:38 +02:00
|
|
|
|
2013-11-23 19:20:44 +01:00
|
|
|
# try and locate manual override in the local environment
|
|
|
|
|
try:
|
|
|
|
|
from test_elasticsearch.local import get_client as local_get_client
|
2019-05-10 09:16:33 -06:00
|
|
|
|
2016-07-12 18:02:46 +02:00
|
|
|
new_client = local_get_client(**kwargs)
|
2013-11-23 19:20:44 +01:00
|
|
|
except ImportError:
|
|
|
|
|
# fallback to using vanilla client
|
2020-03-10 12:08:03 -05:00
|
|
|
try:
|
|
|
|
|
new_client = test.get_test_client(**kwargs)
|
|
|
|
|
except SkipTest:
|
|
|
|
|
client = False
|
|
|
|
|
raise
|
2014-04-23 01:00:20 +02:00
|
|
|
|
2016-07-12 18:02:46 +02:00
|
|
|
if not kwargs:
|
|
|
|
|
client = new_client
|
|
|
|
|
|
|
|
|
|
return new_client
|
2013-09-28 15:50:14 +02:00
|
|
|
|
2013-05-27 23:02:38 +02:00
|
|
|
|
2020-05-14 16:09:24 -05:00
|
|
|
def setup_module():
|
2014-01-18 21:08:15 +01:00
|
|
|
get_client()
|
2013-08-01 14:47:34 +02:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
|
2014-04-23 01:00:20 +02:00
|
|
|
class ElasticsearchTestCase(BaseTestCase):
|
|
|
|
|
@staticmethod
|
2016-07-12 18:02:46 +02:00
|
|
|
def _get_client(**kwargs):
|
|
|
|
|
return get_client(**kwargs)
|