Skip to content

Commit 5b19512

Browse files
authored
refactor: Move score_render to lms/grades (#37884)
* fix: move score_render to lms
1 parent 592153f commit 5b19512

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

lms/djangoapps/grades/signals/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def handle_external_grader_score(signal, sender, score, **kwargs):
421421
# NOTE: Importing this at module level causes a circular import because
422422
# score_render → block_render → grades signals → back into this module.
423423
# Keeping it inside the handler avoids that by loading it only when needed.
424-
from xmodule.capa.score_render import load_xblock_for_external_grader
424+
from lms.djangoapps.grades.score_render import load_xblock_for_external_grader
425425
instance = load_xblock_for_external_grader(score.user_id,
426426
course_key,
427427
usage_key,

xmodule/capa/tests/test_score_render.py renamed to lms/djangoapps/grades/tests/test_score_render.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Test for xmodule.capa.score_render module
2+
Test for lms.djangoapps.grades.score_render module
33
"""
44

55
import json
@@ -10,8 +10,11 @@
1010

1111
from common.djangoapps.student.models import AnonymousUserId
1212
from common.djangoapps.student.tests.factories import UserFactory
13+
from lms.djangoapps.grades.score_render import (
14+
get_block_for_descriptor_without_access_check,
15+
load_xblock_for_external_grader
16+
)
1317
from lms.djangoapps.grades.signals.handlers import handle_external_grader_score
14-
from xmodule.capa.score_render import get_block_for_descriptor_without_access_check, load_xblock_for_external_grader
1518
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
1619
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory
1720

@@ -59,8 +62,8 @@ def setUp(self):
5962
user=self.user, anonymous_user_id=self.anonymous_user_id, course_id=self.course.id
6063
)
6164

62-
@patch("xmodule.capa.score_render.modulestore")
63-
@patch("xmodule.capa.score_render.FieldDataCache")
65+
@patch("lms.djangoapps.grades.score_render.modulestore")
66+
@patch("lms.djangoapps.grades.score_render.FieldDataCache")
6467
def test_load_xblock_for_external_grader(self, mock_field_data_cache, mock_modulestore):
6568
"""
6669
Test loading an XBlock for external grading.
@@ -70,7 +73,9 @@ def test_load_xblock_for_external_grader(self, mock_field_data_cache, mock_modul
7073
mock_modulestore.return_value.get_item.return_value = MagicMock()
7174
mock_field_data_cache.cache_for_block_descendents.return_value = MagicMock()
7275

73-
with patch("xmodule.capa.score_render.get_block_for_descriptor_without_access_check") as mock_get_block:
76+
with patch(
77+
"lms.djangoapps.grades.score_render.get_block_for_descriptor_without_access_check"
78+
) as mock_get_block:
7479
mock_get_block.return_value = MagicMock()
7580

7681
# Call the function
@@ -84,8 +89,8 @@ def test_load_xblock_for_external_grader(self, mock_field_data_cache, mock_modul
8489
mock_field_data_cache.cache_for_block_descendents.assert_called_once()
8590
mock_get_block.assert_called_once()
8691

87-
@patch("xmodule.capa.score_render.modulestore")
88-
@patch("xmodule.capa.score_render.AnonymousUserId.objects.get")
92+
@patch("lms.djangoapps.grades.score_render.modulestore")
93+
@patch("lms.djangoapps.grades.score_render.AnonymousUserId.objects.get")
8994
def test_load_xblock_for_external_grader_missing_block(self, mock_anon_user, mock_modulestore):
9095
"""
9196
Test that Http404 is raised when the block is not found.
@@ -101,7 +106,7 @@ def test_load_xblock_for_external_grader_missing_block(self, mock_anon_user, moc
101106
self.anonymous_user_id, str(self.course.id), str(self.problem.location), self.course
102107
)
103108

104-
@patch("xmodule.capa.score_render.prepare_runtime_for_user")
109+
@patch("lms.djangoapps.grades.score_render.prepare_runtime_for_user")
105110
def test_get_block_for_descriptor_without_access_check(self, mock_prepare_runtime):
106111
"""
107112
Test initializing an XBlock instance without access checks.
@@ -121,8 +126,8 @@ def test_get_block_for_descriptor_without_access_check(self, mock_prepare_runtim
121126
mock_prepare_runtime.assert_called_once()
122127
block.bind_for_student.assert_called_once()
123128

124-
@patch("xmodule.capa.score_render.modulestore")
125-
@patch("xmodule.capa.score_render.load_xblock_for_external_grader")
129+
@patch("lms.djangoapps.grades.score_render.modulestore")
130+
@patch("lms.djangoapps.grades.score_render.load_xblock_for_external_grader")
126131
def test_handle_external_grader_score_json_string(self, mock_load_xblock, mock_modulestore):
127132
"""
128133
Test handling an external grader score with a JSON string message.
@@ -166,8 +171,8 @@ def test_handle_external_grader_score_json_string(self, mock_load_xblock, mock_m
166171
self.assertIn("queuekey", ajax_args[1])
167172
mock_instance.save.assert_called_once()
168173

169-
@patch("xmodule.capa.score_render.modulestore")
170-
@patch("xmodule.capa.score_render.load_xblock_for_external_grader")
174+
@patch("lms.djangoapps.grades.score_render.modulestore")
175+
@patch("lms.djangoapps.grades.score_render.load_xblock_for_external_grader")
171176
def test_handle_external_grader_score_plain_text(self, mock_load_xblock, mock_modulestore):
172177
"""
173178
Test handling an external grader score with a plain text message.
@@ -200,8 +205,8 @@ def test_handle_external_grader_score_plain_text(self, mock_load_xblock, mock_mo
200205

201206
mock_instance.save.assert_not_called()
202207

203-
@patch("xmodule.capa.score_render.modulestore")
204-
@patch("xmodule.capa.score_render.load_xblock_for_external_grader")
208+
@patch("lms.djangoapps.grades.score_render.modulestore")
209+
@patch("lms.djangoapps.grades.score_render.load_xblock_for_external_grader")
205210
def test_handle_external_grader_score_exception(self, mock_load_xblock, mock_modulestore):
206211
"""
207212
Test handling an exception during score processing.
@@ -225,10 +230,10 @@ def test_handle_external_grader_score_exception(self, mock_load_xblock, mock_mod
225230
with self.assertRaises(Exception):
226231
handle_external_grader_score(None, None, score)
227232

228-
@patch("xmodule.capa.score_render.AnonymousUserId.objects.get")
229-
@patch("xmodule.capa.score_render.modulestore")
230-
@patch("xmodule.capa.score_render.FieldDataCache")
231-
@patch("xmodule.capa.score_render.get_block_for_descriptor_without_access_check")
233+
@patch("lms.djangoapps.grades.score_render.AnonymousUserId.objects.get")
234+
@patch("lms.djangoapps.grades.score_render.modulestore")
235+
@patch("lms.djangoapps.grades.score_render.FieldDataCache")
236+
@patch("lms.djangoapps.grades.score_render.get_block_for_descriptor_without_access_check")
232237
def test_load_xblock_for_external_grader_none_instance(
233238
self, mock_get_block, mock_field_data_cache, mock_modulestore, mock_anon_user
234239
):
@@ -276,13 +281,13 @@ def setUp(self):
276281
user=self.user, anonymous_user_id=self.anonymous_user_id, course_id=self.course.id
277282
)
278283

279-
@patch("xmodule.capa.score_render.modulestore")
284+
@patch("lms.djangoapps.grades.score_render.modulestore")
280285
def test_end_to_end_grading_flow(self, mock_modulestore): # pylint: disable=unused-argument
281286
"""
282287
Test the end-to-end flow from receiving a score event to updating the grade.
283288
"""
284289
# Mock the internal call to load_xblock_for_external_grader
285-
with patch("xmodule.capa.score_render.load_xblock_for_external_grader") as mock_load_xblock:
290+
with patch("lms.djangoapps.grades.score_render.load_xblock_for_external_grader") as mock_load_xblock:
286291
# Setup the mock XBlock instance
287292
mock_instance = MagicMock()
288293
mock_load_xblock.return_value = mock_instance

0 commit comments

Comments
 (0)