API: Fix crash PRETIXEU-AN5

This commit is contained in:
Raphael Michel
2024-10-09 12:25:36 +02:00
parent 1dda2eb4fb
commit 221f14cc21
2 changed files with 25 additions and 8 deletions
+12 -8
View File
@@ -88,16 +88,20 @@ class SalesChannelMigrationMixin:
}
if data.get("all_sales_channels") and set(data["sales_channels"]) != all_channels:
raise ValidationError(
"If 'all_sales_channels' is set, the legacy attribute 'sales_channels' must not be set or set to "
"the list of all sales channels."
)
raise ValidationError({
"limit_sales_channels": [
"If 'all_sales_channels' is set, the legacy attribute 'sales_channels' must not be set or set to "
"the list of all sales channels."
]
})
if data.get("limit_sales_channels") and set(data["sales_channels"]) != set(data["limit_sales_channels"]):
raise ValidationError(
"If 'limit_sales_channels' is set, the legacy attribute 'sales_channels' must not be set or set to "
"the same list."
)
raise ValidationError({
"limit_sales_channels": [
"If 'limit_sales_channels' is set, the legacy attribute 'sales_channels' must not be set or set to "
"the same list."
]
})
if data["sales_channels"] == all_channels:
data["all_sales_channels"] = True
+13
View File
@@ -807,6 +807,19 @@ def test_event_update_plugins_validation(token_client, organizer, event, item, m
)
assert resp.status_code == 200
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/'.format(organizer.slug, event.slug),
{
"all_sales_channels": False,
"limit_sales_channels": ["web"],
"sales_channels": ["bar"],
},
format='json'
)
assert resp.status_code == 400
assert resp.content.decode() == ('{"limit_sales_channels":["If \'limit_sales_channels\' is set, the legacy '
'attribute \'sales_channels\' must not be set or set to the same list."]}')
@pytest.mark.django_db
def test_event_test_mode(token_client, organizer, event):