Skip to content

Commit f509f10

Browse files
authored
[7.11] Fix config of client pytest fixtures
1 parent fa39846 commit f509f10

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

Diff for: elasticsearch/helpers/test.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
from elasticsearch import Elasticsearch
2525
from elasticsearch.exceptions import ConnectionError
2626

27+
if "ELASTICSEARCH_URL" in os.environ:
28+
ELASTICSEARCH_URL = os.environ["ELASTICSEARCH_URL"]
29+
elif os.environ.get("TEST_SUITE") == "platinum":
30+
ELASTICSEARCH_URL = "https://elastic:changeme@localhost:9200"
31+
else:
32+
ELASTICSEARCH_URL = "http://localhost:9200"
33+
2734

2835
def get_test_client(nowait=False, **kwargs):
2936
# construct kwargs from the environment
@@ -37,7 +44,7 @@ def get_test_client(nowait=False, **kwargs):
3744
)
3845

3946
kw.update(kwargs)
40-
client = Elasticsearch(os.environ.get("ELASTICSEARCH_URL", {}), **kw)
47+
client = Elasticsearch(ELASTICSEARCH_URL, **kw)
4148

4249
# wait for yellow status
4350
for _ in range(1 if nowait else 100):

Diff for: elasticsearch/helpers/test.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ from typing import Any, Tuple
1919
from unittest import TestCase
2020
from ..client import Elasticsearch
2121

22+
ELASTICSEARCH_URL: str
23+
2224
def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ...
2325
def _get_version(version_string: str) -> Tuple[int, ...]: ...
2426

Diff for: test_elasticsearch/test_async/test_server/conftest.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import os
19-
import pytest
2018
import asyncio
19+
20+
import pytest
2121
import elasticsearch
22+
from elasticsearch.helpers.test import ELASTICSEARCH_URL
23+
2224
from ...utils import wipe_cluster
2325

2426
pytestmark = pytest.mark.asyncio
@@ -31,15 +33,8 @@ async def async_client():
3133
if not hasattr(elasticsearch, "AsyncElasticsearch"):
3234
pytest.skip("test requires 'AsyncElasticsearch'")
3335

34-
kw = {
35-
"timeout": 3,
36-
"ca_certs": ".ci/certs/ca.pem",
37-
"connection_class": elasticsearch.AIOHttpConnection,
38-
}
39-
40-
client = elasticsearch.AsyncElasticsearch(
41-
[os.environ.get("ELASTICSEARCH_HOST", {})], **kw
42-
)
36+
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
37+
client = elasticsearch.AsyncElasticsearch(ELASTICSEARCH_URL, **kw)
4338

4439
# wait for yellow status
4540
for _ in range(100):

Diff for: test_elasticsearch/test_server/conftest.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,24 @@
1919
import time
2020
import pytest
2121
import elasticsearch
22+
from elasticsearch.helpers.test import ELASTICSEARCH_URL
23+
2224
from ..utils import wipe_cluster
2325

2426

2527
@pytest.fixture(scope="function")
2628
def sync_client():
2729
client = None
2830
try:
29-
kw = {
30-
"timeout": 3,
31-
"ca_certs": ".ci/certs/ca.pem",
32-
"connection_class": getattr(
33-
elasticsearch,
34-
os.environ.get("PYTHON_CONNECTION_CLASS", "Urllib3HttpConnection"),
35-
),
36-
}
37-
38-
client = elasticsearch.Elasticsearch(
39-
[os.environ.get("ELASTICSEARCH_URL", {})], **kw
40-
)
31+
kw = {"timeout": 3, "ca_certs": ".ci/certs/ca.pem"}
32+
if "PYTHON_CONNECTION_CLASS" in os.environ:
33+
from elasticsearch import connection
34+
35+
kw["connection_class"] = getattr(
36+
connection, os.environ["PYTHON_CONNECTION_CLASS"]
37+
)
38+
39+
client = elasticsearch.Elasticsearch(ELASTICSEARCH_URL, **kw)
4140

4241
# wait for yellow status
4342
for _ in range(100):

Diff for: test_elasticsearch/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def wipe_cluster_settings(client):
7070
for name, value in settings.items():
7171
if value:
7272
new_settings.setdefault(name, {})
73-
for key in name.keys():
73+
for key in value.keys():
7474
new_settings[name][key + ".*"] = None
7575
if new_settings:
7676
client.cluster.put_settings(body=new_settings)
@@ -103,7 +103,6 @@ def wipe_data_streams(client):
103103

104104

105105
def wipe_indices(client):
106-
107106
client.indices.delete(
108107
index="*",
109108
expand_wildcards="all",

0 commit comments

Comments
 (0)