Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/mock_vws/_flask_server/target_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ def delete_vumark_database(database_name: str) -> Response:

:status 200: The VuMark database has been deleted.
"""
(matching_database,) = {
database
for database in TARGET_MANAGER.vumark_databases
if database_name == database.database_name
}
try:
(matching_database,) = {
database
for database in TARGET_MANAGER.vumark_databases
if database_name == database.database_name
}
except ValueError:
return Response(response="", status=HTTPStatus.NOT_FOUND)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueError conflates not-found and duplicates

Low Severity

delete_vumark_database catches any ValueError from the single-item unpack, so both “no matches” and “multiple matches” return HTTPStatus.NOT_FOUND. If duplicate database_names ever exist (e.g., due to state corruption or future changes), the endpoint silently reports 404 instead of surfacing the invariant violation.

Fix in Cursor Fix in Web


TARGET_MANAGER.remove_vumark_database(vumark_database=matching_database)
return Response(response="", status=HTTPStatus.OK)

Expand Down
27 changes: 27 additions & 0 deletions tests/mock_vws/test_flask_app_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,33 @@ def test_delete_database() -> None:
response = requests.delete(url=delete_url, json={}, timeout=30)
assert response.status_code == HTTPStatus.NOT_FOUND

@staticmethod
def test_vumark_not_found() -> None:
"""
A 404 error is returned when trying to delete a VuMark database
which
does not exist.
"""
databases_url = _EXAMPLE_URL_FOR_TARGET_MANAGER + "/vumark_databases"
delete_url = databases_url + "/" + "foobar"
response = requests.delete(url=delete_url, json={}, timeout=30)
assert response.status_code == HTTPStatus.NOT_FOUND

@staticmethod
def test_delete_vumark_database() -> None:
"""It is possible to delete a VuMark database."""
databases_url = _EXAMPLE_URL_FOR_TARGET_MANAGER + "/vumark_databases"
response = requests.post(url=databases_url, json={}, timeout=30)
assert response.status_code == HTTPStatus.CREATED

data = json.loads(s=response.text)
delete_url = databases_url + "/" + data["database_name"]
response = requests.delete(url=delete_url, json={}, timeout=30)
assert response.status_code == HTTPStatus.OK

response = requests.delete(url=delete_url, json={}, timeout=30)
assert response.status_code == HTTPStatus.NOT_FOUND


class TestQueryImageMatchers:
"""Tests for query image matchers."""
Expand Down