fix: when no option selected, the criteria should try to create

This commit is contained in:
Leangseu Kim
2023-06-05 12:38:17 -04:00
committed by leangseu-edx
parent cef8c062a2
commit 40613ae3f4
2 changed files with 24 additions and 1 deletions

View File

@@ -305,7 +305,8 @@ class StaffAssessSerializer(serializers.Serializer):
def get_options_selected(self, instance):
options_selected = {}
for criterion in instance.get("criteria"):
options_selected[criterion["name"]] = criterion["selectedOption"]
if criterion["selectedOption"]:
options_selected[criterion["name"]] = criterion["selectedOption"]
return options_selected

View File

@@ -718,6 +718,13 @@ class TestStaffAssessSerializer(TestCase):
],
}
grade_data_no_selected_option = {
"overallFeedback": "was pretty good",
"criteria": [
{"name": "firstCriterion", "selectedOption": None},
],
}
submission_uuid = "foo"
def test_staff_assess_serializer(self):
@@ -757,3 +764,18 @@ class TestStaffAssessSerializer(TestCase):
}
assert serializer.data == expected_value
def test_staff_assess_no_selected_option(self):
"""When selected option is None, it should be ignored"""
context = {"submission_uuid": self.submission_uuid}
serializer = StaffAssessSerializer(self.grade_data_no_selected_option, context=context)
expected_value = {
"options_selected": {},
"criterion_feedback": {},
"overall_feedback": "was pretty good",
"submission_uuid": self.submission_uuid,
"assess_type": "full-grade",
}
assert serializer.data == expected_value