Skip to content

Commit caaf55b

Browse files
committed
update test(s)
1 parent 1e034ba commit caaf55b

File tree

7 files changed

+120
-20
lines changed

7 files changed

+120
-20
lines changed

stac_fastapi/elasticsearch/tests/api/test_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import uuid
33
from datetime import datetime, timedelta
44

5+
import pytest
6+
57
from ..conftest import create_collection, create_item
68

79
ROUTES = {
@@ -31,17 +33,20 @@
3133
}
3234

3335

36+
@pytest.mark.asyncio
3437
async def test_post_search_content_type(app_client, ctx):
3538
params = {"limit": 1}
3639
resp = await app_client.post("/search", json=params)
3740
assert resp.headers["content-type"] == "application/geo+json"
3841

3942

43+
@pytest.mark.asyncio
4044
async def test_get_search_content_type(app_client, ctx):
4145
resp = await app_client.get("/search")
4246
assert resp.headers["content-type"] == "application/geo+json"
4347

4448

49+
@pytest.mark.asyncio
4550
async def test_api_headers(app_client):
4651
resp = await app_client.get("/api")
4752
assert (
@@ -50,11 +55,13 @@ async def test_api_headers(app_client):
5055
assert resp.status_code == 200
5156

5257

58+
@pytest.mark.asyncio
5359
async def test_router(app):
5460
api_routes = set([f"{list(route.methods)[0]} {route.path}" for route in app.routes])
5561
assert len(api_routes - ROUTES) == 0
5662

5763

64+
@pytest.mark.asyncio
5865
async def test_app_transaction_extension(app_client, ctx):
5966
item = copy.deepcopy(ctx.item)
6067
item["id"] = str(uuid.uuid4())
@@ -64,6 +71,7 @@ async def test_app_transaction_extension(app_client, ctx):
6471
await app_client.delete(f"/collections/{item['collection']}/items/{item['id']}")
6572

6673

74+
@pytest.mark.asyncio
6775
async def test_app_search_response(app_client, ctx):
6876
resp = await app_client.get("/search", params={"ids": ["test-item"]})
6977
assert resp.status_code == 200
@@ -75,6 +83,7 @@ async def test_app_search_response(app_client, ctx):
7583
assert resp_json.get("stac_extensions") is None
7684

7785

86+
@pytest.mark.asyncio
7887
async def test_app_context_extension(app_client, ctx, txn_client):
7988
test_item = ctx.item
8089
test_item["id"] = "test-item-2"
@@ -108,13 +117,15 @@ async def test_app_context_extension(app_client, ctx, txn_client):
108117
assert matched == 1
109118

110119

120+
@pytest.mark.asyncio
111121
async def test_app_fields_extension(app_client, ctx, txn_client):
112122
resp = await app_client.get("/search", params={"collections": ["test-collection"]})
113123
assert resp.status_code == 200
114124
resp_json = resp.json()
115125
assert list(resp_json["features"][0]["properties"]) == ["datetime"]
116126

117127

128+
@pytest.mark.asyncio
118129
async def test_app_fields_extension_query(app_client, ctx, txn_client):
119130
resp = await app_client.post(
120131
"/search",
@@ -128,6 +139,7 @@ async def test_app_fields_extension_query(app_client, ctx, txn_client):
128139
assert list(resp_json["features"][0]["properties"]) == ["datetime", "proj:epsg"]
129140

130141

142+
@pytest.mark.asyncio
131143
async def test_app_fields_extension_no_properties_get(app_client, ctx, txn_client):
132144
resp = await app_client.get(
133145
"/search", params={"collections": ["test-collection"], "fields": "-properties"}
@@ -137,6 +149,7 @@ async def test_app_fields_extension_no_properties_get(app_client, ctx, txn_clien
137149
assert "properties" not in resp_json["features"][0]
138150

139151

152+
@pytest.mark.asyncio
140153
async def test_app_fields_extension_no_properties_post(app_client, ctx, txn_client):
141154
resp = await app_client.post(
142155
"/search",
@@ -150,6 +163,7 @@ async def test_app_fields_extension_no_properties_post(app_client, ctx, txn_clie
150163
assert "properties" not in resp_json["features"][0]
151164

152165

166+
@pytest.mark.asyncio
153167
async def test_app_fields_extension_return_all_properties(app_client, ctx, txn_client):
154168
item = ctx.item
155169
resp = await app_client.get(
@@ -166,6 +180,7 @@ async def test_app_fields_extension_return_all_properties(app_client, ctx, txn_c
166180
assert feature["properties"][expected_prop] == expected_value
167181

168182

183+
@pytest.mark.asyncio
169184
async def test_app_query_extension_gt(app_client, ctx):
170185
params = {"query": {"proj:epsg": {"gt": ctx.item["properties"]["proj:epsg"]}}}
171186
resp = await app_client.post("/search", json=params)
@@ -174,6 +189,7 @@ async def test_app_query_extension_gt(app_client, ctx):
174189
assert len(resp_json["features"]) == 0
175190

176191

192+
@pytest.mark.asyncio
177193
async def test_app_query_extension_gte(app_client, ctx):
178194
params = {"query": {"proj:epsg": {"gte": ctx.item["properties"]["proj:epsg"]}}}
179195
resp = await app_client.post("/search", json=params)
@@ -182,22 +198,26 @@ async def test_app_query_extension_gte(app_client, ctx):
182198
assert len(resp.json()["features"]) == 1
183199

184200

201+
@pytest.mark.asyncio
185202
async def test_app_query_extension_limit_lt0(app_client):
186203
assert (await app_client.post("/search", json={"limit": -1})).status_code == 400
187204

188205

206+
@pytest.mark.asyncio
189207
async def test_app_query_extension_limit_gt10000(app_client):
190208
resp = await app_client.post("/search", json={"limit": 10001})
191209
assert resp.status_code == 200
192210
assert resp.json()["context"]["limit"] == 10000
193211

194212

213+
@pytest.mark.asyncio
195214
async def test_app_query_extension_limit_10000(app_client):
196215
params = {"limit": 10000}
197216
resp = await app_client.post("/search", json=params)
198217
assert resp.status_code == 200
199218

200219

220+
@pytest.mark.asyncio
201221
async def test_app_sort_extension(app_client, txn_client, ctx):
202222
first_item = ctx.item
203223
item_date = datetime.strptime(
@@ -223,6 +243,7 @@ async def test_app_sort_extension(app_client, txn_client, ctx):
223243
assert resp_json["features"][1]["id"] == second_item["id"]
224244

225245

246+
@pytest.mark.asyncio
226247
async def test_search_invalid_date(app_client, ctx):
227248
params = {
228249
"datetime": "2020-XX-01/2020-10-30",
@@ -233,6 +254,7 @@ async def test_search_invalid_date(app_client, ctx):
233254
assert resp.status_code == 400
234255

235256

257+
@pytest.mark.asyncio
236258
async def test_search_point_intersects(app_client, ctx):
237259
point = [150.04, -33.14]
238260
intersects = {"type": "Point", "coordinates": point}
@@ -248,6 +270,7 @@ async def test_search_point_intersects(app_client, ctx):
248270
assert len(resp_json["features"]) == 1
249271

250272

273+
@pytest.mark.asyncio
251274
async def test_search_point_does_not_intersect(app_client, ctx):
252275
point = [15.04, -3.14]
253276
intersects = {"type": "Point", "coordinates": point}
@@ -263,6 +286,7 @@ async def test_search_point_does_not_intersect(app_client, ctx):
263286
assert len(resp_json["features"]) == 0
264287

265288

289+
@pytest.mark.asyncio
266290
async def test_datetime_non_interval(app_client, ctx):
267291
dt_formats = [
268292
"2020-02-12T12:30:22+00:00",
@@ -284,6 +308,7 @@ async def test_datetime_non_interval(app_client, ctx):
284308
assert resp_json["features"][0]["properties"]["datetime"][0:19] == dt[0:19]
285309

286310

311+
@pytest.mark.asyncio
287312
async def test_bbox_3d(app_client, ctx):
288313
australia_bbox = [106.343365, -47.199523, 0.1, 168.218365, -19.437288, 0.1]
289314
params = {
@@ -296,6 +321,7 @@ async def test_bbox_3d(app_client, ctx):
296321
assert len(resp_json["features"]) == 1
297322

298323

324+
@pytest.mark.asyncio
299325
async def test_search_line_string_intersects(app_client, ctx):
300326
line = [[150.04, -33.14], [150.22, -33.89]]
301327
intersects = {"type": "LineString", "coordinates": line}

stac_fastapi/elasticsearch/tests/clients/test_elasticsearch.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ..conftest import MockRequest, create_item
1212

1313

14+
@pytest.mark.asyncio
1415
async def test_create_collection(app_client, ctx, core_client, txn_client):
1516
in_coll = deepcopy(ctx.collection)
1617
in_coll["id"] = str(uuid.uuid4())
@@ -20,6 +21,7 @@ async def test_create_collection(app_client, ctx, core_client, txn_client):
2021
await txn_client.delete_collection(in_coll["id"])
2122

2223

24+
@pytest.mark.asyncio
2325
async def test_create_collection_already_exists(app_client, ctx, txn_client):
2426
data = deepcopy(ctx.collection)
2527

@@ -32,6 +34,7 @@ async def test_create_collection_already_exists(app_client, ctx, txn_client):
3234
await txn_client.delete_collection(data["id"])
3335

3436

37+
@pytest.mark.asyncio
3538
async def test_update_collection(
3639
core_client,
3740
txn_client,
@@ -49,6 +52,7 @@ async def test_update_collection(
4952
await txn_client.delete_collection(data["id"])
5053

5154

55+
@pytest.mark.asyncio
5256
async def test_delete_collection(
5357
core_client,
5458
txn_client,
@@ -63,6 +67,7 @@ async def test_delete_collection(
6367
await core_client.get_collection(data["id"], request=MockRequest)
6468

6569

70+
@pytest.mark.asyncio
6671
async def test_get_collection(
6772
core_client,
6873
txn_client,
@@ -76,6 +81,7 @@ async def test_get_collection(
7681
await txn_client.delete_collection(data["id"])
7782

7883

84+
@pytest.mark.asyncio
7985
async def test_get_item(app_client, ctx, core_client):
8086
got_item = await core_client.get_item(
8187
item_id=ctx.item["id"],
@@ -86,6 +92,7 @@ async def test_get_item(app_client, ctx, core_client):
8692
assert got_item["collection"] == ctx.item["collection"]
8793

8894

95+
@pytest.mark.asyncio
8996
async def test_get_collection_items(app_client, ctx, core_client, txn_client):
9097
coll = ctx.collection
9198
num_of_items_to_create = 5
@@ -106,6 +113,7 @@ async def test_get_collection_items(app_client, ctx, core_client, txn_client):
106113
assert item["collection"] == coll["id"]
107114

108115

116+
@pytest.mark.asyncio
109117
async def test_create_item(ctx, core_client, txn_client):
110118
resp = await core_client.get_item(
111119
ctx.item["id"], ctx.item["collection"], request=MockRequest
@@ -115,6 +123,7 @@ async def test_create_item(ctx, core_client, txn_client):
115123
) == Item(**resp).dict(exclude={"links": ..., "properties": {"created", "updated"}})
116124

117125

126+
@pytest.mark.asyncio
118127
async def test_create_item_already_exists(ctx, txn_client):
119128
with pytest.raises(ConflictError):
120129
await txn_client.create_item(
@@ -125,6 +134,7 @@ async def test_create_item_already_exists(ctx, txn_client):
125134
)
126135

127136

137+
@pytest.mark.asyncio
128138
async def test_update_item(ctx, core_client, txn_client):
129139
ctx.item["properties"]["foo"] = "bar"
130140
collection_id = ctx.item["collection"]
@@ -139,6 +149,7 @@ async def test_update_item(ctx, core_client, txn_client):
139149
assert updated_item["properties"]["foo"] == "bar"
140150

141151

152+
@pytest.mark.asyncio
142153
async def test_update_geometry(ctx, core_client, txn_client):
143154
new_coordinates = [
144155
[
@@ -163,6 +174,7 @@ async def test_update_geometry(ctx, core_client, txn_client):
163174
assert updated_item["geometry"]["coordinates"] == new_coordinates
164175

165176

177+
@pytest.mark.asyncio
166178
async def test_delete_item(ctx, core_client, txn_client):
167179
await txn_client.delete_item(ctx.item["id"], ctx.item["collection"])
168180

@@ -172,6 +184,7 @@ async def test_delete_item(ctx, core_client, txn_client):
172184
)
173185

174186

187+
@pytest.mark.asyncio
175188
async def test_bulk_item_insert(ctx, core_client, txn_client, bulk_txn_client):
176189
items = {}
177190
for _ in range(10):
@@ -193,6 +206,7 @@ async def test_bulk_item_insert(ctx, core_client, txn_client, bulk_txn_client):
193206
# )
194207

195208

209+
@pytest.mark.asyncio
196210
async def test_feature_collection_insert(
197211
core_client,
198212
txn_client,

stac_fastapi/elasticsearch/tests/extensions/test_filter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from os import listdir
44
from os.path import isfile, join
55

6+
import pytest
7+
68
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
79

810

11+
@pytest.mark.asyncio
912
async def test_search_filters(app_client, ctx):
1013

1114
filters = []
@@ -19,6 +22,7 @@ async def test_search_filters(app_client, ctx):
1922
assert resp.status_code == 200
2023

2124

25+
@pytest.mark.asyncio
2226
async def test_search_filter_extension_eq(app_client, ctx):
2327
params = {"filter": {"op": "=", "args": [{"property": "id"}, ctx.item["id"]]}}
2428
resp = await app_client.post("/search", json=params)
@@ -27,6 +31,7 @@ async def test_search_filter_extension_eq(app_client, ctx):
2731
assert len(resp_json["features"]) == 1
2832

2933

34+
@pytest.mark.asyncio
3035
async def test_search_filter_extension_gte(app_client, ctx):
3136
# there's one item that can match, so one of these queries should match it and the other shouldn't
3237
params = {
@@ -58,6 +63,7 @@ async def test_search_filter_extension_gte(app_client, ctx):
5863
assert len(resp.json()["features"]) == 0
5964

6065

66+
@pytest.mark.asyncio
6167
async def test_search_filter_ext_and(app_client, ctx):
6268
params = {
6369
"filter": {
@@ -80,6 +86,7 @@ async def test_search_filter_ext_and(app_client, ctx):
8086
assert len(resp.json()["features"]) == 1
8187

8288

89+
@pytest.mark.asyncio
8390
async def test_search_filter_extension_floats(app_client, ctx):
8491
sun_elevation = ctx.item["properties"]["view:sun_elevation"]
8592

0 commit comments

Comments
 (0)