def test_addbadhint(self): """ Check that instructors cannot add hints with unparsable answers. """ # Patching. hinter = MagicMock() hinter.validate_answer = lambda string: False request = RequestFactory() post = request.post( self.url, { "field": "mod_queue", "op": "add hint", "problem": self.problem_id.to_deprecated_string(), "answer": "fish", "hint": "This is a new hint.", }, ) post.user = "******" with patch("courseware.module_render.get_module", MagicMock(return_value=hinter)): with patch("courseware.model_data.FieldDataCache", MagicMock(return_value=None)): view.add_hint(post, self.course_id, "mod_queue") problem_hints = XModuleUserStateSummaryField.objects.get(field_name="mod_queue", usage_id=self.problem_id).value self.assertTrue("fish" not in json.loads(problem_hints))
def test_addbadhint(self): """ Check that instructors cannot add hints with unparsable answers. """ # Patching. hinter = MagicMock() hinter.validate_answer = lambda string: False request = RequestFactory() post = request.post( self.url, { 'field': 'mod_queue', 'op': 'add hint', 'problem': self.problem_id.to_deprecated_string(), 'answer': 'fish', 'hint': 'This is a new hint.' }) post.user = '******' with patch('courseware.module_render.get_module', MagicMock(return_value=hinter)): with patch('courseware.model_data.FieldDataCache', MagicMock(return_value=None)): view.add_hint(post, self.course_id, 'mod_queue') problem_hints = XModuleUserStateSummaryField.objects.get( field_name='mod_queue', usage_id=self.problem_id).value self.assertTrue('fish' not in json.loads(problem_hints))
def test_addhint(self): """ Check that instructors can add new hints. """ request = RequestFactory() post = request.post(self.url, {'field': 'mod_queue', 'op': 'add hint', 'problem': self.problem_id, 'answer': '3.14', 'hint': 'This is a new hint.'}) view.add_hint(post, self.course_id, 'mod_queue') problem_hints = XModuleContentField.objects.get(field_name='mod_queue', definition_id=self.problem_id).value self.assertTrue('3.14' in json.loads(problem_hints))
def test_addhint(self): """ Check that instructors can add new hints. """ request = RequestFactory() post = request.post( self.url, { 'field': 'mod_queue', 'op': 'add hint', 'problem': self.problem_id, 'answer': '3.14', 'hint': 'This is a new hint.' }) view.add_hint(post, self.course_id, 'mod_queue') problem_hints = XModuleContentField.objects.get( field_name='mod_queue', definition_id=self.problem_id).value self.assertTrue('3.14' in json.loads(problem_hints))
def test_addhint(self): """ Check that instructors can add new hints. """ request = RequestFactory() post = request.post( self.url, { "field": "mod_queue", "op": "add hint", "problem": self.problem_id, "answer": "3.14", "hint": "This is a new hint.", }, ) view.add_hint(post, self.course_id, "mod_queue") problem_hints = XModuleContentField.objects.get(field_name="mod_queue", definition_id=self.problem_id).value self.assertTrue("3.14" in json.loads(problem_hints))
def test_addbadhint(self): """ Check that instructors cannot add hints with unparsable answers. """ # Patching. hinter = MagicMock() hinter.validate_answer = lambda string: False request = RequestFactory() post = request.post(self.url, {'field': 'mod_queue', 'op': 'add hint', 'problem': self.problem_id.to_deprecated_string(), 'answer': 'fish', 'hint': 'This is a new hint.'}) post.user = '******' with patch('courseware.module_render.get_module', MagicMock(return_value=hinter)): with patch('courseware.model_data.FieldDataCache', MagicMock(return_value=None)): view.add_hint(post, self.course_id, 'mod_queue') problem_hints = XModuleUserStateSummaryField.objects.get(field_name='mod_queue', usage_id=self.problem_id).value self.assertTrue('fish' not in json.loads(problem_hints))
def test_addhint(self): """ Check that instructors can add new hints. """ # Because add_hint accesses the xmodule, this test requires a bunch # of monkey patching. hinter = MagicMock() hinter.validate_answer = lambda string: True request = RequestFactory() post = request.post(self.url, {'field': 'mod_queue', 'op': 'add hint', 'problem': self.problem_id, 'answer': '3.14', 'hint': 'This is a new hint.'}) post.user = '******' with patch('courseware.module_render.get_module', MagicMock(return_value=hinter)): with patch('courseware.model_data.ModelDataCache', MagicMock(return_value=None)): view.add_hint(post, self.course_id, 'mod_queue') problem_hints = XModuleContentField.objects.get(field_name='mod_queue', definition_id=self.problem_id).value self.assertTrue('3.14' in json.loads(problem_hints))