File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed
test_elasticsearch_serverless Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 21
21
22
22
from elasticsearch_serverless import Elasticsearch
23
23
24
- from .utils import es_url , es_version
24
+ from .utils import es_api_key , es_url , es_version
25
25
26
26
27
27
@pytest .fixture (scope = "session" )
@@ -32,6 +32,14 @@ def elasticsearch_url():
32
32
pytest .skip (str (e ))
33
33
34
34
35
+ @pytest .fixture (scope = "session" )
36
+ def elasticsearch_api_key ():
37
+ try :
38
+ return es_api_key ()
39
+ except RuntimeError as e :
40
+ pytest .skip (str (e ))
41
+
42
+
35
43
@pytest .fixture (scope = "session" )
36
44
def elasticsearch_version (elasticsearch_url ) -> Tuple [int , ...]:
37
45
"""Returns the version of the current Elasticsearch cluster"""
Original file line number Diff line number Diff line change 27
27
28
28
@pytest_asyncio .fixture (scope = "function" )
29
29
@pytest .mark .usefixtures ("sync_client" )
30
- async def async_client (elasticsearch_url ):
30
+ async def async_client (elasticsearch_url , elasticsearch_api_key ):
31
31
# 'sync_client' fixture is used for the guaranteed wipe_cluster() call.
32
32
33
33
if not hasattr (elasticsearch_serverless , "AsyncElasticsearch" ):
@@ -39,7 +39,7 @@ async def async_client(elasticsearch_url):
39
39
client = None
40
40
try :
41
41
client = elasticsearch_serverless .AsyncElasticsearch (
42
- elasticsearch_url , request_timeout = 3
42
+ elasticsearch_url , api_key = elasticsearch_api_key , request_timeout = 3
43
43
)
44
44
yield client
45
45
finally :
Original file line number Diff line number Diff line change 21
21
22
22
import elasticsearch_serverless
23
23
24
- from ..utils import es_api_key , wipe_cluster
24
+ from ..utils import wipe_cluster
25
25
26
26
# Information about the Elasticsearch instance running, if any
27
27
# Used for
31
31
32
32
33
33
@pytest .fixture (scope = "session" )
34
- def sync_client_factory (elasticsearch_url ):
34
+ def sync_client_factory (elasticsearch_url , elasticsearch_api_key ):
35
35
client = None
36
36
try :
37
37
# Configure the client with API key and optionally
38
38
# an HTTP conn class depending on 'PYTHON_CONNECTION_CLASS' envvar
39
- kw = {}
39
+ kw = {'api_key' : elasticsearch_api_key }
40
40
if "PYTHON_CONNECTION_CLASS" in os .environ :
41
41
kw ["node_class" ] = os .environ ["PYTHON_CONNECTION_CLASS" ]
42
42
43
43
# We do this little dance with the URL to force
44
44
# Requests to respect 'headers: None' within rest API spec tests.
45
45
client = elasticsearch_serverless .Elasticsearch (
46
- elasticsearch_url , api_key = es_api_key (), ** kw
46
+ elasticsearch_url , ** kw
47
47
)
48
48
49
49
# Wipe the cluster before we start testing just in case it wasn't wiped
You can’t perform that action at this time.
0 commit comments