mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
Questions: Validate type changes (Z#23197118) (#5259)
* Questions: Validate type changes (Z#23197118) * Update src/pretix/base/forms/questions.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/base/forms/questions.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/base/forms/questions.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Update src/pretix/base/models/items.py Co-authored-by: Richard Schreiber <schreiber@rami.io> * Fix failing test --------- Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
@@ -2428,6 +2428,45 @@ def test_question_update(token_client, organizer, event, question):
|
||||
assert question.type == "N"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_question_update_type_changes(token_client, organizer, event, question):
|
||||
# Allowed because no answers exist
|
||||
resp = token_client.patch(
|
||||
'/api/v1/organizers/{}/events/{}/questions/{}/'.format(organizer.slug, event.slug, question.pk),
|
||||
{
|
||||
"type": "B",
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
with scopes_disabled():
|
||||
question.answers.create(answer="12")
|
||||
|
||||
# Allowed change
|
||||
resp = token_client.patch(
|
||||
'/api/v1/organizers/{}/events/{}/questions/{}/'.format(organizer.slug, event.slug, question.pk),
|
||||
{
|
||||
"type": "S",
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
# Forbidden change
|
||||
resp = token_client.patch(
|
||||
'/api/v1/organizers/{}/events/{}/questions/{}/'.format(organizer.slug, event.slug, question.pk),
|
||||
{
|
||||
"type": "B",
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert resp.content.decode() == ('{"type":["The system already contains answers to this question that are not '
|
||||
'compatible with changing the type of question without data loss. Consider hiding '
|
||||
'this question and creating a new one instead."]}')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_question_update_circular_dependency(token_client, organizer, event, question):
|
||||
with scopes_disabled():
|
||||
|
||||
Reference in New Issue
Block a user