mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-17 23:37:35 -04:00
fix: return HTTP 400 for duplicate tag and label creation (#7638)
Co-authored-by: voidborne-d <voidborne-d@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,21 @@ def create_labels(api_client: TestClient, unique_user: TestUser, count: int = 10
|
||||
return labels
|
||||
|
||||
|
||||
def test_label_create_duplicate_name_returns_400(api_client: TestClient, unique_user_fn_scoped: TestUser):
|
||||
# Regression test for #7582: POSTing a duplicate label name leaked the
|
||||
# sqlalchemy IntegrityError as an HTTP 500. The expected behavior, matching
|
||||
# the other organizer endpoints (foods, units, tools, tags, categories),
|
||||
# is HTTP 400. The function-scoped fixture avoids leaking the created label
|
||||
# into the module-scoped `unique_user` group state used by sibling tests.
|
||||
payload = {"name": random_string(), "color": "#ff0000"}
|
||||
|
||||
response = api_client.post(api_routes.groups_labels, json=payload, headers=unique_user_fn_scoped.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = api_client.post(api_routes.groups_labels, json=payload, headers=unique_user_fn_scoped.token)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_new_list_creates_list_labels(api_client: TestClient, unique_user: TestUser):
|
||||
labels = create_labels(api_client, unique_user)
|
||||
response = api_client.post(
|
||||
|
||||
Reference in New Issue
Block a user