1+ import os
12import uuid
23from copy import deepcopy
34from typing import Callable
45
56import pytest
67from stac_pydantic import Item , api
78
9+ if os .getenv ("BACKEND" , "elasticsearch" ).lower () == "opensearch" :
10+ from elasticsearch import exceptions
11+ else :
12+ from opensearchpy import exceptions
13+
814from stac_fastapi .extensions .third_party .bulk_transactions import Items
915from stac_fastapi .types .errors import ConflictError , NotFoundError
1016from stac_fastapi .types .stac import PatchAddReplaceTest , PatchMoveCopy , PatchRemove
@@ -265,15 +271,14 @@ async def test_merge_patch_item_remove(ctx, core_client, txn_client):
265271 await txn_client .merge_patch_item (
266272 collection_id = collection_id ,
267273 item_id = item_id ,
268- item = {"properties" : {"foo" : None , "hello " : None }},
274+ item = {"properties" : {"gsd " : None }},
269275 request = MockRequest ,
270276 )
271277
272278 updated_item = await core_client .get_item (
273279 item_id , collection_id , request = MockRequest
274280 )
275- assert "foo" not in updated_item ["properties" ]
276- assert "hello" not in updated_item ["properties" ]
281+ assert "gsd" not in updated_item ["properties" ]
277282
278283
279284@pytest .mark .asyncio
@@ -298,7 +303,7 @@ async def test_json_patch_item_add(ctx, core_client, txn_client):
298303 item_id , collection_id , request = MockRequest
299304 )
300305
301- assert updated_item ["properties" ]["bar " ] == "foo "
306+ assert updated_item ["properties" ]["foo " ] == "bar "
302307
303308
304309@pytest .mark .asyncio
@@ -308,7 +313,7 @@ async def test_json_patch_item_replace(ctx, core_client, txn_client):
308313 item_id = item ["id" ]
309314 operations = [
310315 PatchAddReplaceTest .model_validate (
311- {"op" : "replace" , "path" : "properties.foo " , "value" : 100 }
316+ {"op" : "replace" , "path" : "properties.gsd " , "value" : 100 }
312317 ),
313318 ]
314319
@@ -323,7 +328,7 @@ async def test_json_patch_item_replace(ctx, core_client, txn_client):
323328 item_id , collection_id , request = MockRequest
324329 )
325330
326- assert updated_item ["properties" ]["foo " ] == 100
331+ assert updated_item ["properties" ]["gsd " ] == 100
327332
328333
329334@pytest .mark .asyncio
@@ -333,7 +338,7 @@ async def test_json_patch_item_test(ctx, core_client, txn_client):
333338 item_id = item ["id" ]
334339 operations = [
335340 PatchAddReplaceTest .model_validate (
336- {"op" : "test" , "path" : "properties.foo " , "value" : 100 }
341+ {"op" : "test" , "path" : "properties.gsd " , "value" : 15 }
337342 ),
338343 ]
339344
@@ -348,7 +353,7 @@ async def test_json_patch_item_test(ctx, core_client, txn_client):
348353 item_id , collection_id , request = MockRequest
349354 )
350355
351- assert updated_item ["properties" ]["foo " ] == 100
356+ assert updated_item ["properties" ]["gsd " ] == 15
352357
353358
354359@pytest .mark .asyncio
@@ -358,7 +363,7 @@ async def test_json_patch_item_move(ctx, core_client, txn_client):
358363 item_id = item ["id" ]
359364 operations = [
360365 PatchMoveCopy .model_validate (
361- {"op" : "move" , "path" : "properties.bar" , "from" : "properties.foo " }
366+ {"op" : "move" , "path" : "properties.bar" , "from" : "properties.gsd " }
362367 ),
363368 ]
364369
@@ -373,8 +378,8 @@ async def test_json_patch_item_move(ctx, core_client, txn_client):
373378 item_id , collection_id , request = MockRequest
374379 )
375380
376- assert updated_item ["properties" ]["bar" ] == 100
377- assert "foo " not in updated_item ["properties" ]
381+ assert updated_item ["properties" ]["bar" ] == 15
382+ assert "gsd " not in updated_item ["properties" ]
378383
379384
380385@pytest .mark .asyncio
@@ -384,7 +389,7 @@ async def test_json_patch_item_copy(ctx, core_client, txn_client):
384389 item_id = item ["id" ]
385390 operations = [
386391 PatchMoveCopy .model_validate (
387- {"op" : "copy" , "path" : "properties.foo" , "from" : "properties.bar " }
392+ {"op" : "copy" , "path" : "properties.foo" , "from" : "properties.gsd " }
388393 ),
389394 ]
390395
@@ -399,7 +404,7 @@ async def test_json_patch_item_copy(ctx, core_client, txn_client):
399404 item_id , collection_id , request = MockRequest
400405 )
401406
402- assert updated_item ["properties" ]["foo" ] == updated_item ["properties" ]["bar " ]
407+ assert updated_item ["properties" ]["foo" ] == updated_item ["properties" ]["gsd " ]
403408
404409
405410@pytest .mark .asyncio
@@ -408,8 +413,7 @@ async def test_json_patch_item_remove(ctx, core_client, txn_client):
408413 collection_id = item ["collection" ]
409414 item_id = item ["id" ]
410415 operations = [
411- PatchRemove .model_validate ({"op" : "remove" , "path" : "properties.foo" }),
412- PatchRemove .model_validate ({"op" : "remove" , "path" : "properties.bar" }),
416+ PatchRemove .model_validate ({"op" : "remove" , "path" : "properties.gsd" }),
413417 ]
414418
415419 await txn_client .json_patch_item (
@@ -423,8 +427,7 @@ async def test_json_patch_item_remove(ctx, core_client, txn_client):
423427 item_id , collection_id , request = MockRequest
424428 )
425429
426- assert "foo" not in updated_item ["properties" ]
427- assert "bar" not in updated_item ["properties" ]
430+ assert "gsd" not in updated_item ["properties" ]
428431
429432
430433@pytest .mark .asyncio
@@ -438,7 +441,7 @@ async def test_json_patch_item_test_wrong_value(ctx, core_client, txn_client):
438441 ),
439442 ]
440443
441- with pytest .raises (ConflictError ):
444+ with pytest .raises (exceptions . BadRequestError ):
442445
443446 await txn_client .json_patch_item (
444447 collection_id = collection_id ,
@@ -461,7 +464,7 @@ async def test_json_patch_item_replace_property_does_not_exists(
461464 ),
462465 ]
463466
464- with pytest .raises (ConflictError ):
467+ with pytest .raises (exceptions . BadRequestError ):
465468
466469 await txn_client .json_patch_item (
467470 collection_id = collection_id ,
@@ -482,7 +485,7 @@ async def test_json_patch_item_remove_property_does_not_exists(
482485 PatchRemove .model_validate ({"op" : "remove" , "path" : "properties.foo" }),
483486 ]
484487
485- with pytest .raises (ConflictError ):
488+ with pytest .raises (exceptions . BadRequestError ):
486489
487490 await txn_client .json_patch_item (
488491 collection_id = collection_id ,
@@ -505,7 +508,7 @@ async def test_json_patch_item_move_property_does_not_exists(
505508 ),
506509 ]
507510
508- with pytest .raises (ConflictError ):
511+ with pytest .raises (exceptions . BadRequestError ):
509512
510513 await txn_client .json_patch_item (
511514 collection_id = collection_id ,
@@ -528,7 +531,7 @@ async def test_json_patch_item_copy_property_does_not_exists(
528531 ),
529532 ]
530533
531- with pytest .raises (ConflictError ):
534+ with pytest .raises (exceptions . BadRequestError ):
532535
533536 await txn_client .json_patch_item (
534537 collection_id = collection_id ,
0 commit comments