Skip to content

Commit b5f9787

Browse files
authored
Fix mapbox tests (#44)
* Fix mapbox tests Using `elasticsearch_url` does not work in serverless as API key authentication is required. Also, `node_class` parametrization does not make sense, we parametrize at the CI job level. And finally, the sync case was missing a refresh. * Fix lint, improve condition
1 parent 1afa78a commit b5f9787

File tree

4 files changed

+15
-26
lines changed

4 files changed

+15
-26
lines changed

test_elasticsearch_serverless/test_async/test_server/test_helpers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,7 @@ async def test_errors_are_reported_correctly(self, async_client):
347347
assert "42" == error["index"]["_id"]
348348
assert "i" == error["index"]["_index"]
349349
print(error["index"]["error"])
350-
assert "MapperParsingException" in repr(
351-
error["index"]["error"]
352-
) or "mapper_parsing_exception" in repr(error["index"]["error"])
350+
assert error["index"]["error"]["type"] == "document_parsing_exception"
353351

354352
async def test_error_is_raised(self, async_client):
355353
await async_client.indices.create(

test_elasticsearch_serverless/test_async/test_server/test_mapbox_vector_tile.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919
import pytest_asyncio
2020

21-
from elasticsearch_serverless import AsyncElasticsearch, RequestError
21+
from elasticsearch_serverless 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):
78-
client = AsyncElasticsearch(elasticsearch_url)
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):
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):
114113
}
115114

116115

117-
async def test_mapbox_vector_tile_response(elasticsearch_url, mvt_setup):
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)
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_serverless/test_server/test_helpers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,7 @@ def test_errors_are_reported_correctly(sync_client):
338338
assert "42" == error["index"]["_id"]
339339
assert "i" == error["index"]["_index"]
340340
print(error["index"]["error"])
341-
assert "MapperParsingException" in repr(
342-
error["index"]["error"]
343-
) or "mapper_parsing_exception" in repr(error["index"]["error"])
341+
assert error["index"]["error"]["type"] == "document_parsing_exception"
344342

345343

346344
def test_error_is_raised(sync_client):

test_elasticsearch_serverless/test_server/test_mapbox_vector_tile.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import pytest
1919

20-
from elasticsearch_serverless import Elasticsearch, RequestError
20+
from elasticsearch_serverless import RequestError
2121

2222

2323
@pytest.fixture(scope="function")
@@ -67,13 +67,12 @@ def mvt_setup(sync_client):
6767
"included": True,
6868
},
6969
],
70+
refresh=True,
7071
)
7172

7273

73-
@pytest.mark.parametrize("node_class", ["urllib3", "requests"])
74-
def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, node_class):
75-
client = Elasticsearch(elasticsearch_url, node_class=node_class)
76-
client.search_mvt(
74+
def test_mapbox_vector_tile_error(sync_client, mvt_setup):
75+
sync_client.search_mvt(
7776
index="museums",
7877
zoom=13,
7978
x=4207,
@@ -82,7 +81,7 @@ def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, node_class):
8281
)
8382

8483
with pytest.raises(RequestError) as e:
85-
client.search_mvt(
84+
sync_client.search_mvt(
8685
index="museums",
8786
zoom=-100,
8887
x=4207,
@@ -111,16 +110,13 @@ def test_mapbox_vector_tile_error(elasticsearch_url, mvt_setup, node_class):
111110
}
112111

113112

114-
@pytest.mark.parametrize("node_class", ["urllib3", "requests"])
115-
def test_mapbox_vector_tile_response(elasticsearch_url, mvt_setup, node_class):
113+
def test_mapbox_vector_tile_response(sync_client, mvt_setup):
116114
try:
117115
import mapbox_vector_tile
118116
except ImportError:
119117
return pytest.skip("Requires the 'mapbox-vector-tile' package")
120118

121-
client = Elasticsearch(elasticsearch_url, node_class=node_class)
122-
123-
resp = client.search_mvt(
119+
resp = sync_client.search_mvt(
124120
index="museums",
125121
zoom=13,
126122
x=4207,

0 commit comments

Comments
 (0)