def test_preprocess_problem(self): problem_tree = self._build_problem( RF.MultipleChoiceResponseXMLFactory().build_xml(), RF.MultipleChoiceResponseXMLFactory().build_xml(), RF.MultipleChoiceResponseXMLFactory().build_xml()) self.problem_module.data = problem_tree problem_monitor = ProblemMonitor(self.problem_module) for question_monitor in problem_monitor.question_monitors.values(): self.assertTrue( isinstance(question_monitor, QM.MultipleChoiceMonitor))
def test_preprocess_problem_with_context(self): problem_tree = self._build_problem( RF.MultipleChoiceResponseXMLFactory().build_xml( question_text='First question, who am I ?'), "<p>Second question, whot are you ?</p>", RF.MultipleChoiceResponseXMLFactory().build_xml( question_text='Choose the best answer.')) self.problem_module.data = problem_tree problem_monitor = ProblemMonitor(self.problem_module) question_monitors = problem_monitor.question_monitors self.assertEqual(len(question_monitors), 2) self.assertEqual( len(question_monitors[self._build_question_id(0)].context), 1) self.assertEqual( len(question_monitors[self._build_question_id(1)].context), 2) for element in question_monitors[self._build_question_id(1)].context: self.assertEqual(element.tag, 'p')
def test_get_student_answers(self): first_question = RF.MultipleChoiceResponseXMLFactory().build_xml( choices=[True, False, False]) second_question = RF.MultipleChoiceResponseXMLFactory().build_xml( choices=[False, True, False]) self.problem_module.data = self._build_problem(first_question, second_question) problem_monitor = ProblemMonitor(self.problem_module) cmap = self._build_correct_map('correct', 'incorrect') student_answers = self._build_student_answers('choice_0', 'choice_2') StudentModuleFactory(course_id=self.course.id, state=self._build_student_module_state( cmap, student_answers)) problem_monitor.get_student_answers() correctness_first_question = problem_monitor.question_monitors[ self._build_question_id(0)].correctness student_answers_first_question = problem_monitor.question_monitors[ self._build_question_id(1)].student_answers correctness_second_question = problem_monitor.question_monitors[ self._build_question_id(1)].correctness student_answers_second_question = problem_monitor.question_monitors[ self._build_question_id(1)].student_answers self.assertDictContainsSubset(correctness_first_question, { 'correct': 1, 'incorrect': 0 }) self.assertDictContainsSubset(student_answers_first_question, {'choice_0': 1}) self.assertDictContainsSubset(correctness_second_question, { 'correct': 0, 'incorrect': 1 }) self.assertDictContainsSubset(student_answers_second_question, {'choice_2': 1})
def test_preprocess_problem_with_not_handled_question(self): problem_tree = self._build_problem( RF.MultipleChoiceResponseXMLFactory().build_xml(), RF.SymbolicResponseXMLFactory().build_xml(), RF.MultipleChoiceResponseXMLFactory().build_xml()) self.problem_module.data = problem_tree problem_monitor = ProblemMonitor(self.problem_module) question_monitors = problem_monitor.question_monitors self.assertEqual(len(question_monitors), 3) self.assertTrue( isinstance(question_monitors[self._build_question_id(0)], QM.MultipleChoiceMonitor)) self.assertTrue( isinstance(question_monitors[self._build_question_id(1)], QM.UnhandledQuestionMonitor)) self.assertTrue( isinstance(question_monitors[self._build_question_id(2)], QM.MultipleChoiceMonitor))
def setUp(self): problem_tree = RF.MultipleChoiceResponseXMLFactory().build_xml() question_tree = etree.fromstring(problem_tree).find( 'multiplechoiceresponse') self.label_text = "What colour was Henri IV's white horse?" question_tree = self.add_label_to_choicegroup(question_tree, self.label_text) self.question_monitor = QuestionMonitor(1, question_tree, None) self.question_monitor.student_answers = { 'choice_0': 10, 'choice_1': 42 } self.question_monitor.correctness = { 'correct': '10', 'incorrect': '42' }
def test_get_problem_size(self): self.problem_module.data = RF.MultipleChoiceResponseXMLFactory( ).build_xml() size = utils.get_problem_size(self.problem_module) self.assertEqual(size, 1)