Skip to content

Commit 8d381ac

Browse files
authored
Use client fixtures for mapbox tests (#2579)
* Use client fixtures for mapbox tests * Fix lint * Improve mapbox tests
1 parent cd88015 commit 8d381ac

File tree

4 files changed

+13
-34
lines changed

4 files changed

+13
-34
lines changed

test_elasticsearch/test_async/test_server/test_helpers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,7 @@ async def test_errors_are_reported_correctly(self, async_client):
350350
assert "42" == error["index"]["_id"]
351351
assert "i" == error["index"]["_index"]
352352
print(error["index"]["error"])
353-
assert error["index"]["error"]["type"] in [
354-
"mapper_parsing_exception",
355-
# Elasticsearch 8.8+: https://github.com/elastic/elasticsearch/pull/92646
356-
"document_parsing_exception",
357-
]
353+
assert error["index"]["error"]["type"] == "document_parsing_exception"
358354

359355
async def test_error_is_raised(self, async_client):
360356
await async_client.indices.create(

test_elasticsearch/test_async/test_server/test_mapbox_vector_tile.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919
import pytest_asyncio
2020

21-
from elasticsearch import AsyncElasticsearch, RequestError
21+
from elasticsearch import RequestError
2222

2323
pytestmark = pytest.mark.asyncio
2424

@@ -74,9 +74,8 @@ async def mvt_setup(async_client):
7474
)
7575

7676

77-
async def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, ca_certs):
78-
client = AsyncElasticsearch(elasticsearch_url, ca_certs=ca_certs)
79-
await client.search_mvt(
77+
async def test_mapbox_vector_tile_error(async_client, mvt_setup):
78+
await async_client.search_mvt(
8079
index="museums",
8180
zoom=13,
8281
x=4207,
@@ -85,7 +84,7 @@ async def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, ca_certs):
8584
)
8685

8786
with pytest.raises(RequestError) as e:
88-
await client.search_mvt(
87+
await async_client.search_mvt(
8988
index="museums",
9089
zoom=-100,
9190
x=4207,
@@ -114,15 +113,13 @@ async def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, ca_certs):
114113
}
115114

116115

117-
async def test_mapbox_vector_tile_response(elasticsearch_url, mvt_setup, ca_certs):
116+
async def test_mapbox_vector_tile_response(async_client, mvt_setup):
118117
try:
119118
import mapbox_vector_tile
120119
except ImportError:
121120
return pytest.skip("Requires the 'mapbox-vector-tile' package")
122121

123-
client = AsyncElasticsearch(elasticsearch_url, ca_certs=ca_certs)
124-
125-
resp = await client.search_mvt(
122+
resp = await async_client.search_mvt(
126123
index="museums",
127124
zoom=13,
128125
x=4207,

test_elasticsearch/test_server/test_helpers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ def test_errors_are_reported_correctly(sync_client):
337337
assert "42" == error["index"]["_id"]
338338
assert "i" == error["index"]["_index"]
339339
print(error["index"]["error"])
340-
assert error["index"]["error"]["type"] in [
341-
"mapper_parsing_exception",
342-
# Elasticsearch 8.8+: https://github.com/elastic/elasticsearch/pull/92646
343-
"document_parsing_exception",
344-
]
340+
assert error["index"]["error"]["type"] == "document_parsing_exception"
345341

346342

347343
def test_error_is_raised(sync_client):

test_elasticsearch/test_server/test_mapbox_vector_tile.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
from elasticsearch import RequestError
2121

22-
from .conftest import _create
23-
2422

2523
@pytest.fixture(scope="function")
2624
def mvt_setup(sync_client):
@@ -73,11 +71,8 @@ def mvt_setup(sync_client):
7371
)
7472

7573

76-
@pytest.mark.parametrize("node_class", ["urllib3", "requests"])
77-
def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, node_class, ca_certs):
78-
client = _create(elasticsearch_url, node_class=node_class)
79-
80-
client.search_mvt(
74+
def test_mapbox_vector_tile_error(sync_client, mvt_setup):
75+
sync_client.search_mvt(
8176
index="museums",
8277
zoom=13,
8378
x=4207,
@@ -86,7 +81,7 @@ def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, node_class, ca_c
8681
)
8782

8883
with pytest.raises(RequestError) as e:
89-
client.search_mvt(
84+
sync_client.search_mvt(
9085
index="museums",
9186
zoom=-100,
9287
x=4207,
@@ -115,18 +110,13 @@ def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, node_class, ca_c
115110
}
116111

117112

118-
@pytest.mark.parametrize("node_class", ["urllib3", "requests"])
119-
def test_mapbox_vector_tile_response(
120-
elasticsearch_url, mvt_setup, node_class, ca_certs
121-
):
113+
def test_mapbox_vector_tile_response(sync_client, mvt_setup):
122114
try:
123115
import mapbox_vector_tile
124116
except ImportError:
125117
return pytest.skip("Requires the 'mapbox-vector-tile' package")
126118

127-
client = _create(elasticsearch_url, node_class=node_class)
128-
129-
resp = client.search_mvt(
119+
resp = sync_client.search_mvt(
130120
index="museums",
131121
zoom=13,
132122
x=4207,

0 commit comments

Comments
 (0)