add validation to ItemCategorySerializer

This commit is contained in:
Mira Weller
2024-07-26 20:05:03 +02:00
parent 537a0993b0
commit badbb64f4f
2 changed files with 50 additions and 0 deletions
+38
View File
@@ -214,6 +214,44 @@ def test_category_update(token_client, organizer, event, team, category):
assert ItemCategory.objects.get(pk=category.pk).name == {"en": "Test"}
@pytest.mark.django_db
def test_category_update_cross_selling_options(token_client, organizer, event, team, category):
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/categories/{}/'.format(organizer.slug, event.slug, category.pk),
{
"cross_selling_mode": "both",
},
format='json'
)
assert resp.status_code == 200
with scopes_disabled():
assert ItemCategory.objects.get(pk=category.pk).cross_selling_mode == 'both'
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/categories/{}/'.format(organizer.slug, event.slug, category.pk),
{
"cross_selling_mode": "something",
},
format='json'
)
assert resp.status_code == 400
with scopes_disabled():
assert ItemCategory.objects.get(pk=category.pk).cross_selling_mode == 'both'
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/categories/{}/'.format(organizer.slug, event.slug, category.pk),
{
"is_addon": True,
},
format='json'
)
assert resp.status_code == 400
assert 'mutually exclusive' in str(resp.data)
with scopes_disabled():
assert ItemCategory.objects.get(pk=category.pk).cross_selling_mode == 'both'
assert ItemCategory.objects.get(pk=category.pk).is_addon is False
@pytest.mark.django_db
def test_category_update_wrong_event(token_client, organizer, event2, category):
resp = token_client.patch(