diff --git a/edx_sga/sga.py b/edx_sga/sga.py index 21b9581e..acc5898c 100644 --- a/edx_sga/sga.py +++ b/edx_sga/sga.py @@ -653,7 +653,6 @@ def get_student_item_dict(self, student_id=None): """ if student_id is None and (user_service := self.runtime.service(self, 'user')): student_id = user_service.get_current_user().opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID) - assert student_id != ("MOCK", "Forgot to call 'personalize' in test.") return { "student_id": student_id, @@ -747,18 +746,10 @@ def student_state(self): """ Returns a JSON serializable representation of student's state for rendering in client view. - """ - graded = None + """ submission = self.get_submission() - if submission: uploaded = {"filename": submission["answer"]["filename"]} - student_item = SubmissionsStudent.objects.get(id = submission.get("student_item")) - score = submissions_api.get_score(student_item.student_item_dict) - if score: - score = score.get("points_earned") - graded = {"score": score, "comment": force_str(self.comment)} - else: uploaded = None @@ -766,6 +757,12 @@ def student_state(self): annotated = {"filename": force_str(self.annotated_filename)} else: annotated = None + + score = self.score + if score is not None: + graded = {"score": score, "comment": force_str(self.comment)} + else: + graded = None if self.answer_available() and (replace_urls_service := self.runtime.service(self, 'replace_urls')): solution = replace_urls_service.replace_urls(force_str(self.solution)) diff --git a/edx_sga/tests/integration_tests.py b/edx_sga/tests/integration_tests.py index 10daf7af..49da0f6a 100644 --- a/edx_sga/tests/integration_tests.py +++ b/edx_sga/tests/integration_tests.py @@ -299,7 +299,8 @@ def test_student_view_with_score(self, fragment, render_template): user = student["module"].student student_id = anonymous_id_for_user(user,self.course_id) - with mock.patch.object(StaffGradedAssignmentXBlock.get_submission,"__defaults__",(student_id,)): + with mock.patch.object(StaffGradedAssignmentXBlock.get_submission,"__defaults__",(student_id,)),\ + mock.patch.object(StaffGradedAssignmentXBlock.get_score, "__defaults__",(student_id,)): fragment = block.student_view() render_template.assert_called_once() template_arg = render_template.call_args[0][0] @@ -308,7 +309,6 @@ def test_student_view_with_score(self, fragment, render_template): self.assertEqual(context["is_course_staff"], True) self.assertEqual(context["id"], "d_0") student_state = json.loads(context["student_state"]) - print(f"state: {student_state}") self.assertEqual(student_state["display_name"], "Staff Graded Assignment") self.assertEqual(student_state["uploaded"], {"filename": "foo.txt"}) self.assertEqual(student_state["annotated"], None)