Skip to content

Commit

Permalink
Merge pull request #12307 from rtibbles/so_random
Browse files Browse the repository at this point in the history
Allow quiz level learners see fixed order to be edited after a quiz is opened.
  • Loading branch information
rtibbles authored Jun 20, 2024
2 parents 0e1ff08 + b092f7b commit 8e46ec2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
12 changes: 3 additions & 9 deletions kolibri/core/exams/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ def validate(self, attrs):
code=error_constants.INVALID,
)

if "learners_see_fixed_order" in attrs and is_non_draft_exam:
raise ValidationError(
"Cannot update learners_see_fixed_order on an Exam object",
code=error_constants.INVALID,
)

return attrs

def create(self, validated_data):
Expand Down Expand Up @@ -273,6 +267,9 @@ def update(self, instance, validated_data): # noqa
instance_is_draft = False
# Update the scalar fields
instance.title = validated_data.pop("title", instance.title)
instance.learners_see_fixed_order = validated_data.pop(
"learners_see_fixed_order", instance.learners_see_fixed_order
)
if not instance_is_draft:
# Update the non-draft specific fields
instance.active = validated_data.pop("active", instance.active)
Expand All @@ -286,9 +283,6 @@ def update(self, instance, validated_data): # noqa
instance.question_sources = validated_data.pop(
"question_sources", instance.question_sources
)
instance.learners_see_fixed_order = validated_data.pop(
"learners_see_fixed_order", instance.learners_see_fixed_order
)

# Add/delete any new/removed Assignments
if "assignments" in validated_data:
Expand Down
21 changes: 8 additions & 13 deletions kolibri/core/exams/test/test_exam_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ def test_exam_question_max_length(self):
response = self.post_new_exam(exam)
self.assertEqual(response.status_code, 400)

def test_admin_can_update_learner_sees_fixed_order(self):
self.login_as_admin()
response = self.patch_updated_exam(
self.exam.id, {"learners_see_fixed_order": True}
)
self.assertEqual(response.status_code, 200)
self.assertExamExists(id=self.exam.id, learners_see_fixed_order=True)


class ExamAPITestCase(BaseExamTest, APITestCase):
class_object = models.Exam
Expand Down Expand Up @@ -578,19 +586,6 @@ def test_logged_in_admin_exam_update_cannot_update_question_sources(self):
self.exam.refresh_from_db()
self.assertEqual(self.exam.question_sources, previous_sections)

def test_logged_in_admin_exam_update_cannot_update_learners_see_fixed_order(self):
self.login_as_admin()
previous_learners_see_fixed_order = self.exam.learners_see_fixed_order
response = self.patch_updated_exam(
self.exam.id,
{"learners_see_fixed_order": not previous_learners_see_fixed_order},
)
self.assertEqual(response.status_code, 400)
self.exam.refresh_from_db()
self.assertEqual(
self.exam.learners_see_fixed_order, previous_learners_see_fixed_order
)

def test_logged_in_admin_exam_can_create_and_publish_remove_empty_sections(self):
self.login_as_admin()
exam = self.make_basic_exam()
Expand Down

0 comments on commit 8e46ec2

Please sign in to comment.