def test_xqueue_callback_missing_header_info(self): data = {"xqueue_header": "{}", "xqueue_body": "hello world"} with patch("courseware.module_render.find_target_student_module") as get_fake_module: get_fake_module.return_value = self.mock_module # Test with missing xqueue data with self.assertRaises(Http404): request = self.request_factory.post(self.callback_url, {}) render.xqueue_callback(request, self.course_key, self.mock_user.id, self.mock_module.id, self.dispatch) # Test with missing xqueue_header with self.assertRaises(Http404): request = self.request_factory.post(self.callback_url, data) render.xqueue_callback(request, self.course_key, self.mock_user.id, self.mock_module.id, self.dispatch)
def test_xqueue_callback_missing_header_info(self): data = { 'xqueue_header': '{}', 'xqueue_body': 'hello world', } with patch('courseware.module_render.find_target_student_module') as get_fake_module: get_fake_module.return_value = self.mock_module # Test with missing xqueue data with self.assertRaises(Http404): request = self.request_factory.post(self.callback_url, {}) render.xqueue_callback(request, self.course_id, self.mock_user.id, self.mock_module.id, self.dispatch) # Test with missing xqueue_header with self.assertRaises(Http404): request = self.request_factory.post(self.callback_url, data) render.xqueue_callback(request, self.course_id, self.mock_user.id, self.mock_module.id, self.dispatch)
def test_xqueue_callback_success(self): """ Test for happy-path xqueue_callback """ fake_key = "fake key" xqueue_header = json.dumps({"lms_key": fake_key}) data = {"xqueue_header": xqueue_header, "xqueue_body": "hello world"} # Patch getmodule to return our mock module with patch("courseware.module_render.find_target_student_module") as get_fake_module: get_fake_module.return_value = self.mock_module # call xqueue_callback with our mocked information request = self.request_factory.post(self.callback_url, data) render.xqueue_callback(request, self.course_key, self.mock_user.id, self.mock_module.id, self.dispatch) # Verify that handle ajax is called with the correct data request.POST["queuekey"] = fake_key self.mock_module.handle_ajax.assert_called_once_with(self.dispatch, request.POST)
def test_xqueue_callback_success(self): """ Test for happy-path xqueue_callback """ fake_key = 'fake key' xqueue_header = json.dumps({'lms_key': fake_key}) data = { 'xqueue_header': xqueue_header, 'xqueue_body': 'hello world', } # Patch getmodule to return our mock module with patch('courseware.module_render.find_target_student_module') as get_fake_module: get_fake_module.return_value = self.mock_module # call xqueue_callback with our mocked information request = self.request_factory.post(self.callback_url, data) render.xqueue_callback(request, self.course_id, self.mock_user.id, self.mock_module.id, self.dispatch) # Verify that handle ajax is called with the correct data request.POST['queuekey'] = fake_key self.mock_module.handle_ajax.assert_called_once_with(self.dispatch, request.POST)