Skip to content

Commit 324907c

Browse files
committed
Adding headers for mock patches.
1 parent 6a29945 commit 324907c

File tree

3 files changed

+114
-86
lines changed

3 files changed

+114
-86
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,21 @@ async def json_patch_item(
10441044
wait_for_completion=True,
10451045
refresh=True,
10461046
)
1047+
1048+
await self.delete_item(
1049+
item_id=item_id,
1050+
collection_id=collection_id,
1051+
refresh=refresh,
1052+
)
1053+
10471054
item["collection"] = new_collection_id
1055+
collection_id = new_collection_id
10481056

10491057
if new_item_id:
10501058
item["id"] = new_item_id
1051-
item = await self.prep_create_item(item=item, base_url=base_url)
1059+
item = await self.async_prep_create_item(item=item, base_url=base_url)
10521060
await self.create_item(item=item, refresh=False)
10531061

1054-
if new_collection_id or new_item_id:
1055-
10561062
await self.delete_item(
10571063
item_id=item_id,
10581064
collection_id=collection_id,

stac_fastapi/tests/api/test_api.py

Lines changed: 11 additions & 9 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 create_collection, create_item
10+
from ..conftest import MockRequest, create_collection, create_item
1111

1212
ROUTES = {
1313
"GET /_mgmt/ping",
@@ -625,12 +625,12 @@ async def test_patch_json_collection(app_client, ctx):
625625
"summaries": {"hello": "world", "gsd": [50], "instruments": None},
626626
}
627627

628-
resp = await app_client.patch(f"collections/{ctx.collection['id']}", json=data)
628+
resp = await app_client.patch(f"/collections/{ctx.collection['id']}", json=data)
629629

630630
assert resp.status_code == 200
631631

632-
new_resp = await app_client.get("collections/new_id")
633-
old_resp = await app_client.get(f"collections/{ctx.collection['id']}")
632+
new_resp = await app_client.get("/collections/new_id")
633+
old_resp = await app_client.get(f"/collections/{ctx.collection['id']}")
634634

635635
assert new_resp.status_code == 200
636636
assert old_resp.status_code == 404
@@ -658,7 +658,9 @@ async def test_patch_operations_collection(app_client, ctx):
658658
]
659659

660660
resp = await app_client.patch(
661-
f"/collections/{ctx.item['collection']}", json=operations
661+
f"/collections/{ctx.item['collection']}",
662+
json=operations,
663+
request=MockRequest(headers={"Content-type": "application/json-patch+json"}),
662664
)
663665

664666
assert resp.status_code == 200
@@ -722,18 +724,18 @@ async def test_patch_operations_item(app_client, ctx):
722724
]
723725

724726
resp = await app_client.patch(
725-
f"/collections/{ctx.item['collection']}/{ctx.item['id']}", json=operations
727+
f"/collections/{ctx.item['collection']}/{ctx.item['id']}",
728+
json=operations,
729+
request=MockRequest(headers={"Content-type": "application/json-patch+json"}),
726730
)
727731

728732
assert resp.status_code == 200
729733

730-
new_resp = await app_client.get(f"/collections/{ctx.item['collection']}/new_id")
731-
old_resp = await app_client.get(
734+
new_resp = await app_client.get(
732735
f"/collections/{ctx.item['collection']}/{ctx.item['id']}"
733736
)
734737

735738
assert new_resp.status_code == 200
736-
assert old_resp.status_code == 404
737739

738740
new_resp_json = new_resp.json()
739741

0 commit comments

Comments
 (0)