Skip to content

Commit

Permalink
[7.11] Fix config of client pytest fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson authored Feb 5, 2021
1 parent fa39846 commit f509f10
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 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 @@ -19,6 +19,8 @@ from typing import Any, Tuple
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
17 changes: 6 additions & 11 deletions test_elasticsearch/test_async/test_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# specific language governing permissions and limitations
# under the License.

import os
import pytest
import asyncio

import pytest
import elasticsearch
from elasticsearch.helpers.test import ELASTICSEARCH_URL

from ...utils import wipe_cluster

pytestmark = pytest.mark.asyncio
Expand All @@ -31,15 +33,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
23 changes: 11 additions & 12 deletions test_elasticsearch/test_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@
import time
import pytest
import elasticsearch
from elasticsearch.helpers.test import ELASTICSEARCH_URL

from ..utils import wipe_cluster


@pytest.fixture(scope="function")
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 @@ -70,7 +70,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 @@ -103,7 +103,6 @@ def wipe_data_streams(client):


def wipe_indices(client):

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

0 comments on commit f509f10

Please sign in to comment.