-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathtest_async_connection.py
63 lines (46 loc) · 1.9 KB
/
test_async_connection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
try:
from elasticsearch._async.http_aiohttp import AsyncConnection
except ImportError:
from elastic_transport._models import NodeConfig
from elastic_transport._node._base_async import BaseAsyncNode as AsyncConnection
from conftest import ES_VERSION, ES_SETTINGS
HOST = {"scheme": "http", "host": ES_SETTINGS["host"], "port": int(ES_SETTINGS["port"])}
IS_V8 = ES_VERSION >= (8,)
SKIP_IF_V7 = pytest.mark.skipif(not IS_V8, reason="Skipping v8 tests.")
SKIP_IF_V8 = pytest.mark.skipif(IS_V8, reason="Skipping v7 tests.")
def test_connection_default():
if IS_V8:
conn = AsyncConnection(NodeConfig(**HOST))
else:
conn = AsyncConnection(**HOST)
assert conn._nr_host_port == (ES_SETTINGS["host"], ES_SETTINGS["port"])
@SKIP_IF_V7
def test_connection_config():
conn = AsyncConnection(NodeConfig(scheme="http", host="foo", port=8888))
assert conn._nr_host_port == ("foo", "8888")
@SKIP_IF_V8
def test_connection_host_arg():
conn = AsyncConnection("the_host")
assert conn._nr_host_port == ("the_host", "9200")
@SKIP_IF_V8
def test_connection_args():
conn = AsyncConnection("the_host", 9999)
assert conn._nr_host_port == ("the_host", "9999")
@SKIP_IF_V8
def test_connection_kwargs():
conn = AsyncConnection(host="foo", port=8888)
assert conn._nr_host_port == ("foo", "8888")