11"""
2- Test for xmodule.capa .score_render module
2+ Test for lms.djangoapps.grades .score_render module
33"""
44
55import json
1010
1111from common .djangoapps .student .models import AnonymousUserId
1212from 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+ )
1317from 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
1518from xmodule .modulestore .tests .django_utils import ModuleStoreTestCase
1619from 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