Skip to content

Commit 9c143c1

Browse files
committed
Removing MockRequest from test_api.py
1 parent c245d55 commit 9c143c1

File tree

4 files changed

+99
-23
lines changed

4 files changed

+99
-23
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ async def merge_patch_item(
958958
Returns:
959959
patched item.
960960
"""
961-
operations = merge_to_operations(item)
961+
operations = merge_to_operations(item.model_dump())
962962

963963
return await self.json_patch_item(
964964
collection_id=collection_id,
@@ -1288,7 +1288,7 @@ async def merge_patch_collection(
12881288
Returns:
12891289
patched collection.
12901290
"""
1291-
operations = merge_to_operations(collection)
1291+
operations = merge_to_operations(collection.model_dump())
12921292

12931293
return await self.json_patch_collection(
12941294
collection_id=collection_id,

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ async def merge_patch_item(
971971
Returns:
972972
patched item.
973973
"""
974-
operations = merge_to_operations(item)
974+
operations = merge_to_operations(item.model_dump())
975975

976976
return await self.json_patch_item(
977977
collection_id=collection_id,
@@ -1269,7 +1269,7 @@ async def merge_patch_collection(
12691269
Returns:
12701270
patched collection.
12711271
"""
1272-
operations = merge_to_operations(collection)
1272+
operations = merge_to_operations(collection.model_dump())
12731273

12741274
return await self.json_patch_collection(
12751275
collection_id=collection_id,

stac_fastapi/tests/api/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from stac_fastapi.types.errors import ConflictError
99

10-
from ..conftest import MockRequest, create_collection, create_item
10+
from ..conftest import create_collection, create_item
1111

1212
ROUTES = {
1313
"GET /_mgmt/ping",
@@ -660,7 +660,7 @@ async def test_patch_operations_collection(app_client, ctx):
660660
resp = await app_client.patch(
661661
f"/collections/{ctx.item['collection']}",
662662
json=operations,
663-
request=MockRequest(headers={"content-type": "application/json-patch+json"}),
663+
headers={"content-type": "application/json-patch+json"},
664664
)
665665

666666
assert resp.status_code == 200
@@ -726,7 +726,7 @@ async def test_patch_operations_item(app_client, ctx):
726726
resp = await app_client.patch(
727727
f"/collections/{ctx.item['collection']}/{ctx.item['id']}",
728728
json=operations,
729-
request=MockRequest(headers={"content-type": "application/json-patch+json"}),
729+
headers={"content-type": "application/json-patch+json"},
730730
)
731731

732732
assert resp.status_code == 200

stac_fastapi/tests/clients/test_es_os.py

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ async def test_merge_patch_item_add(ctx, core_client, txn_client):
247247
collection_id=collection_id,
248248
item_id=item_id,
249249
patch={"properties": {"foo": "bar", "ext:hello": "world"}},
250-
request=MockRequest,
250+
request=MockRequest(headers={"content-type": "application/json"}),
251251
)
252252

253253
updated_item = await core_client.get_item(
@@ -266,7 +266,7 @@ async def test_merge_patch_item_remove(ctx, core_client, txn_client):
266266
collection_id=collection_id,
267267
item_id=item_id,
268268
patch={"properties": {"gsd": None, "proj:epsg": None}},
269-
request=MockRequest,
269+
request=MockRequest(headers={"content-type": "application/merge-patch+json"}),
270270
)
271271

272272
updated_item = await core_client.get_item(
@@ -289,7 +289,17 @@ async def test_json_patch_item_add(ctx, core_client, txn_client):
289289
{"op": "add", "path": "/properties/ext:hello", "value": "world"}
290290
),
291291
PatchAddReplaceTest.model_validate(
292-
{"op": "add", "path": "/properties/area/1", "value": 10}
292+
{
293+
"op": "add",
294+
"path": "/properties/eo:bands/1",
295+
"value": {
296+
"gsd": 10,
297+
"name": "FB",
298+
"common_name": "fake_band",
299+
"center_wavelength": 3.45,
300+
"full_width_half_max": 1.23,
301+
},
302+
}
293303
),
294304
]
295305

@@ -306,7 +316,17 @@ async def test_json_patch_item_add(ctx, core_client, txn_client):
306316

307317
assert updated_item["properties"]["foo"] == "bar"
308318
assert updated_item["properties"]["ext:hello"] == "world"
309-
assert updated_item["properties"]["area"] == [2500, 10, -200]
319+
assert (
320+
len(updated_item["properties"]["eo:bands"])
321+
== len(ctx.item["properties"]["eo:bands"]) + 1
322+
)
323+
assert updated_item["properties"]["eo:bands"][1] == {
324+
"gsd": 10,
325+
"name": "FB",
326+
"common_name": "fake_band",
327+
"center_wavelength": 3.45,
328+
"full_width_half_max": 1.23,
329+
}
310330

311331

312332
@pytest.mark.asyncio
@@ -322,7 +342,17 @@ async def test_json_patch_item_replace(ctx, core_client, txn_client):
322342
{"op": "replace", "path": "/properties/proj:epsg", "value": 12345}
323343
),
324344
PatchAddReplaceTest.model_validate(
325-
{"op": "replace", "path": "/properties/area/1", "value": 50}
345+
{
346+
"op": "replace",
347+
"path": "/properties/eo:bands/1",
348+
"value": {
349+
"gsd": 10,
350+
"name": "FB",
351+
"common_name": "fake_band",
352+
"center_wavelength": 3.45,
353+
"full_width_half_max": 1.23,
354+
},
355+
}
326356
),
327357
]
328358

@@ -339,7 +369,16 @@ async def test_json_patch_item_replace(ctx, core_client, txn_client):
339369

340370
assert updated_item["properties"]["gsd"] == 100
341371
assert updated_item["properties"]["proj:epsg"] == 12345
342-
assert updated_item["properties"]["area"] == [2500, 50]
372+
assert len(updated_item["properties"]["eo:bands"]) == len(
373+
ctx.item["properties"]["eo:bands"]
374+
)
375+
assert updated_item["properties"]["eo:bands"][1] == {
376+
"gsd": 10,
377+
"name": "FB",
378+
"common_name": "fake_band",
379+
"center_wavelength": 3.45,
380+
"full_width_half_max": 1.23,
381+
}
343382

344383

345384
@pytest.mark.asyncio
@@ -355,7 +394,11 @@ async def test_json_patch_item_test(ctx, core_client, txn_client):
355394
{"op": "test", "path": "/properties/proj:epsg", "value": 32756}
356395
),
357396
PatchAddReplaceTest.model_validate(
358-
{"op": "test", "path": "/properties/area/1", "value": -200}
397+
{
398+
"op": "test",
399+
"path": "/properties/eo:bands/1",
400+
"value": item["properties"]["eo:bands"][1],
401+
}
359402
),
360403
]
361404

@@ -372,7 +415,9 @@ async def test_json_patch_item_test(ctx, core_client, txn_client):
372415

373416
assert updated_item["properties"]["gsd"] == 15
374417
assert updated_item["properties"]["proj:epsg"] == 32756
375-
assert updated_item["properties"]["area"][1] == -200
418+
assert (
419+
updated_item["properties"]["eo:bands"][1] == item["properties"]["eo:bands"][1]
420+
)
376421

377422

378423
@pytest.mark.asyncio
@@ -388,7 +433,11 @@ async def test_json_patch_item_move(ctx, core_client, txn_client):
388433
{"op": "move", "path": "/properties/bar", "from": "/properties/proj:epsg"}
389434
),
390435
PatchMoveCopy.model_validate(
391-
{"op": "move", "path": "/properties/area/0", "from": "/properties/area/1"}
436+
{
437+
"op": "move",
438+
"path": "/properties/eo:bands/0",
439+
"from": "/properties/eo:bands/1",
440+
}
392441
),
393442
]
394443

@@ -407,7 +456,17 @@ async def test_json_patch_item_move(ctx, core_client, txn_client):
407456
assert "gsd" not in updated_item["properties"]
408457
assert updated_item["properties"]["bar"] == 32756
409458
assert "proj:epsg" not in updated_item["properties"]
410-
assert updated_item["properties"]["area"] == [-200, 2500]
459+
assert len(updated_item["properties"]["eo:bands"]) == len(
460+
ctx.item["properties"]["eo:bands"]
461+
)
462+
assert (
463+
updated_item["properties"]["eo:bands"][0]
464+
== ctx.item["properties"]["eo:bands"][1]
465+
)
466+
assert (
467+
updated_item["properties"]["eo:bands"][1]
468+
!= ctx.item["properties"]["eo:bands"][1]
469+
)
411470

412471

413472
@pytest.mark.asyncio
@@ -423,7 +482,11 @@ async def test_json_patch_item_copy(ctx, core_client, txn_client):
423482
{"op": "copy", "path": "/properties/bar", "from": "/properties/proj:epsg"}
424483
),
425484
PatchMoveCopy.model_validate(
426-
{"op": "copy", "path": "/properties/area/0", "from": "/properties/area/1"}
485+
{
486+
"op": "copy",
487+
"path": "/properties/eo:bands/0",
488+
"from": "/properties/eo:bands/1",
489+
}
427490
),
428491
]
429492

@@ -441,7 +504,12 @@ async def test_json_patch_item_copy(ctx, core_client, txn_client):
441504
assert updated_item["properties"]["foo"] == updated_item["properties"]["gsd"]
442505
assert updated_item["properties"]["bar"] == updated_item["properties"]["proj:epsg"]
443506
assert (
444-
updated_item["properties"]["area"][0] == updated_item["properties"]["area"][1]
507+
len(updated_item["properties"]["eo:bands"])
508+
== len(ctx.item["properties"]["eo:bands"]) + 1
509+
)
510+
assert (
511+
updated_item["properties"]["eo:bands"][0]
512+
== ctx.item["properties"]["eo:bands"][1]
445513
)
446514

447515

@@ -453,7 +521,7 @@ async def test_json_patch_item_remove(ctx, core_client, txn_client):
453521
operations = [
454522
PatchRemove.model_validate({"op": "remove", "path": "/properties/gsd"}),
455523
PatchRemove.model_validate({"op": "remove", "path": "/properties/proj:epsg"}),
456-
PatchRemove.model_validate({"op": "remove", "path": "/properties/area/1"}),
524+
PatchRemove.model_validate({"op": "remove", "path": "/properties/eo:bands/1"}),
457525
]
458526

459527
await txn_client.patch_item(
@@ -469,7 +537,15 @@ async def test_json_patch_item_remove(ctx, core_client, txn_client):
469537

470538
assert "gsd" not in updated_item["properties"]
471539
assert "proj:epsg" not in updated_item["properties"]
472-
assert updated_item["properties"]["area"] == [2500]
540+
assert (
541+
len(updated_item["properties"]["eo:bands"])
542+
== len(ctx.item["properties"]["eo:bands"]) - 1
543+
)
544+
assert (
545+
updated_item["properties"]["eo:bands"]
546+
== ctx.item["properties"]["eo:bands"][:1]
547+
+ ctx.item["properties"]["eo:bands"][2:]
548+
)
473549

474550

475551
@pytest.mark.asyncio
@@ -653,7 +729,7 @@ async def test_merge_patch_collection_add(ctx, core_client, txn_client):
653729
await txn_client.patch_collection(
654730
collection_id=collection_id,
655731
patch={"summaries": {"foo": "bar", "hello": "world"}},
656-
request=MockRequest,
732+
request=MockRequest(headers={"content-type": "application/json"}),
657733
)
658734

659735
updated_collection = await core_client.get_collection(
@@ -670,7 +746,7 @@ async def test_merge_patch_collection_remove(ctx, core_client, txn_client):
670746
await txn_client.patch_collection(
671747
collection_id=collection_id,
672748
patch={"summaries": {"gsd": None}},
673-
request=MockRequest,
749+
request=MockRequest(headers={"content-type": "application/merge-patch+json"}),
674750
)
675751

676752
updated_collection = await core_client.get_collection(

0 commit comments

Comments
 (0)