Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow quiz level learners see fixed order to be edited after a quiz is opened. #12307

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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