Skip to content

Commit 8e05f13

Browse files
authored
Merge pull request #1046 from RS-PYTHON/fix/rspy439-add-item-in-non-existing-collection
fix-rspy439-add-item-in-non-existing-collection
2 parents 4167210 + a380c97 commit 8e05f13

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

services/catalog/rs_server_catalog/user_catalog.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,13 @@ async def manage_put_post_request( # pylint: disable=too-many-statements,too-ma
753753

754754
# The following section handles the request to create/update an item
755755
elif "items" in request.scope["path"]:
756+
# first check if the collection exists
757+
if not await self.collection_exists(request, f"{self.request_ids['owner_id']}_{collection}"):
758+
raise HTTPException(
759+
status_code=HTTP_404_NOT_FOUND,
760+
detail=f"Collection {collection} does not exist.",
761+
)
762+
756763
# try to get the item if it is already part from the collection
757764
item = await self.get_item_from_collection(request)
758765

services/catalog/tests/test_endpoints.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,6 @@ def test_update_timestamp_feature_fails_with_unfound_item(
16121612
"""
16131613
ENDPOINT: PUT: /catalog/collections/{user:collection}/items/{featureID}
16141614
"""
1615-
16161615
# Change correct feature collection id to match with minimal collection and post it
16171616
a_correct_feature["collection"] = "fixture_collection"
16181617
# Post the correct feature to catalog
@@ -1628,13 +1627,57 @@ def test_update_timestamp_feature_fails_with_unfound_item(
16281627
updated_feature_sent["bbox"] = [77]
16291628
del updated_feature_sent["collection"]
16301629

1631-
path = "/catalog/collections/fixture_owner:fixture_collections/items/NOT_FOUND_ITEM"
1630+
path = "/catalog/collections/fixture_owner:fixture_collection/items/NOT_FOUND_ITEM"
16321631
feature_put_response = client.put(
16331632
path,
16341633
json=updated_feature_sent,
16351634
)
16361635
assert feature_put_response.status_code == fastapi.status.HTTP_400_BAD_REQUEST
16371636

1637+
def test_update_feature_in_non_existing_collection_fails(
1638+
self,
1639+
client,
1640+
a_minimal_collection,
1641+
a_correct_feature,
1642+
):
1643+
"""
1644+
ENDPOINT: PUT: /catalog/collections/{user:collection}/items/{featureID}
1645+
with collection as non existing collection
1646+
"""
1647+
# Change correct feature collection id to match with minimal collection
1648+
a_correct_feature["collection"] = "fixture_collection"
1649+
# Put feature in non existing collection
1650+
non_existing_collection = "NON_EXISTING_FIXTURE_COLLECTION"
1651+
feature_put_response = client.put(
1652+
f"/catalog/collections/fixture_owner:{non_existing_collection}/items/{a_correct_feature['id']}",
1653+
json=a_correct_feature,
1654+
)
1655+
1656+
assert feature_put_response.status_code == fastapi.status.HTTP_404_NOT_FOUND
1657+
assert feature_put_response.json() == f"Collection {non_existing_collection} does not exist."
1658+
1659+
def test_add_feature_in_non_existing_collection_fails(
1660+
self,
1661+
client,
1662+
a_minimal_collection,
1663+
a_correct_feature,
1664+
):
1665+
"""
1666+
ENDPOINT: POST: /catalog/collections/{user:collection}/items/
1667+
with collection as non existing collection
1668+
"""
1669+
# Change correct feature collection id to match with minimal collection and post it
1670+
a_correct_feature["collection"] = "fixture_collection"
1671+
# Post the correct feature to catalog
1672+
non_existing_collection = "NON_EXISTING_FIXTURE_COLLECTION"
1673+
feature_post_response = client.post(
1674+
f"/catalog/collections/fixture_owner:{non_existing_collection}/items",
1675+
json=a_correct_feature,
1676+
)
1677+
1678+
assert feature_post_response.status_code == fastapi.status.HTTP_404_NOT_FOUND
1679+
assert feature_post_response.json() == f"Collection {non_existing_collection} does not exist."
1680+
16381681
def test_update_with_an_incorrect_feature(self, client, a_minimal_collection, a_correct_feature):
16391682
"""Testing POST feature endpoint with a wrong-formatted field (BBOX)."""
16401683
# Change correct feature collection id to match with minimal collection and post it

0 commit comments

Comments
 (0)