Skip to content

Commit

Permalink
[7.x] Fix config of client pytest fixtures
Browse files Browse the repository at this point in the history
Co-authored-by: Seth Michael Larson <seth.larson@elastic.co>
  • Loading branch information
github-actions[bot] and sethmlarson authored Feb 5, 2021
1 parent 9744eae commit 10e76d7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
9 changes: 8 additions & 1 deletion elasticsearch/helpers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
from elasticsearch import Elasticsearch
from elasticsearch.exceptions import ConnectionError

if "ELASTICSEARCH_URL" in os.environ:
ELASTICSEARCH_URL = os.environ["ELASTICSEARCH_URL"]
elif os.environ.get("TEST_SUITE") == "platinum":
ELASTICSEARCH_URL = "https://elastic:changeme@localhost:9200"
else:
ELASTICSEARCH_URL = "http://localhost:9200"


def get_test_client(nowait=False, **kwargs):
# construct kwargs from the environment
Expand All @@ -37,7 +44,7 @@ def get_test_client(nowait=False, **kwargs):
)

kw.update(kwargs)
client = Elasticsearch(os.environ.get("ELASTICSEARCH_URL", {}), **kw)
client = Elasticsearch(ELASTICSEARCH_URL, **kw)

# wait for yellow status
for _ in range(1 if nowait else 100):
Expand Down
2 changes: 2 additions & 0 deletions elasticsearch/helpers/test.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ from unittest import TestCase

from ..client import Elasticsearch

ELASTICSEARCH_URL: str

def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ...
def _get_version(version_string: str) -> Tuple[int, ...]: ...

Expand Down
13 changes: 3 additions & 10 deletions test_elasticsearch/test_async/test_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# under the License.

import asyncio
import os

import pytest

import elasticsearch
from elasticsearch.helpers.test import ELASTICSEARCH_URL

from ...utils import wipe_cluster

Expand All @@ -34,15 +34,8 @@ async def async_client():
if not hasattr(elasticsearch, "AsyncElasticsearch"):
pytest.skip("test requires 'AsyncElasticsearch'")

kw = {
"timeout": 3,
"ca_certs": ".ci/certs/ca.pem",
"connection_class": elasticsearch.AIOHttpConnection,
}

client = elasticsearch.AsyncElasticsearch(
[os.environ.get("ELASTICSEARCH_HOST", {})], **kw
)
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
client = elasticsearch.AsyncElasticsearch(ELASTICSEARCH_URL, **kw)

# wait for yellow status
for _ in range(100):
Expand Down
22 changes: 10 additions & 12 deletions test_elasticsearch/test_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytest

import elasticsearch
from elasticsearch.helpers.test import ELASTICSEARCH_URL

from ..utils import wipe_cluster

Expand All @@ -29,18 +30,15 @@
def sync_client():
client = None
try:
kw = {
"timeout": 3,
"ca_certs": ".ci/certs/ca.pem",
"connection_class": getattr(
elasticsearch,
os.environ.get("PYTHON_CONNECTION_CLASS", "Urllib3HttpConnection"),
),
}

client = elasticsearch.Elasticsearch(
[os.environ.get("ELASTICSEARCH_URL", {})], **kw
)
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
if "PYTHON_CONNECTION_CLASS" in os.environ:
from elasticsearch import connection

kw["connection_class"] = getattr(
connection, os.environ["PYTHON_CONNECTION_CLASS"]
)

client = elasticsearch.Elasticsearch(ELASTICSEARCH_URL, **kw)

# wait for yellow status
for _ in range(100):
Expand Down
3 changes: 1 addition & 2 deletions test_elasticsearch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def wipe_cluster_settings(client):
for name, value in settings.items():
if value:
new_settings.setdefault(name, {})
for key in name.keys():
for key in value.keys():
new_settings[name][key + ".*"] = None
if new_settings:
client.cluster.put_settings(body=new_settings)
Expand Down Expand Up @@ -104,7 +104,6 @@ def wipe_data_streams(client):


def wipe_indices(client):

client.indices.delete(
index="*",
expand_wildcards="all",
Expand Down

0 comments on commit 10e76d7

Please sign in to comment.