From c87f9cd523f3f40fd45efe2c4b6f872965c10204 Mon Sep 17 00:00:00 2001 From: Arjun Singh Date: Thu, 19 Jul 2012 13:07:00 -0700 Subject: [PATCH] Added tests for ChoiceResponses. --- common/lib/capa/capa/responsetypes.py | 2 +- common/lib/xmodule/tests/__init__.py | 27 +++++++++ .../test_files/choiceresponse_checkbox.xml | 59 +++++++++++++++++++ .../tests/test_files/choiceresponse_radio.xml | 40 +++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 common/lib/xmodule/tests/test_files/choiceresponse_checkbox.xml create mode 100644 common/lib/xmodule/tests/test_files/choiceresponse_radio.xml diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index a8137a7eb7..e45a274e6d 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -325,7 +325,7 @@ class ChoiceResponse(LoncapaResponse): def assign_choice_names(self): ''' - Initialize name attributes in tags for his response. + Initialize name attributes in tags for this response. ''' for index, choice in enumerate(self.xml.xpath('//*[@id=$id]//choice', diff --git a/common/lib/xmodule/tests/__init__.py b/common/lib/xmodule/tests/__init__.py index 09c533e390..3d52dad087 100644 --- a/common/lib/xmodule/tests/__init__.py +++ b/common/lib/xmodule/tests/__init__.py @@ -325,6 +325,33 @@ class CodeResponseTest(unittest.TestCase): else: self.assertTrue(test_lcp.correct_map.is_queued(answer_ids[j])) # Should be queued, message undelivered +class ChoiceResponseTest(unittest.TestCase): + + def test_cr_rb_grade(self): + problem_file = os.path.dirname(__file__)+"/test_files/choiceresponse_radio.xml" + test_lcp = lcp.LoncapaProblem(open(problem_file).read(), '1', system=i4xs) + correct_answers = {'1_2_1':'choice_2', + '1_3_1':['choice_2', 'choice_3']} + test_answers = {'1_2_1':'choice_2', + '1_3_1':'choice_2', + } + self.assertEquals(test_lcp.grade_answers(test_answers).get_correctness('1_2_1'), 'correct') + self.assertEquals(test_lcp.grade_answers(test_answers).get_correctness('1_3_1'), 'incorrect') + + def test_cr_cb_grade(self): + problem_file = os.path.dirname(__file__)+"/test_files/choiceresponse_checkbox.xml" + test_lcp = lcp.LoncapaProblem(open(problem_file).read(), '1', system=i4xs) + correct_answers = {'1_2_1':'choice_2', + '1_3_1':['choice_2', 'choice_3'], + '1_4_1':['choice_2', 'choice_3']} + test_answers = {'1_2_1':'choice_2', + '1_3_1':'choice_2', + '1_4_1':['choice_2', 'choice_3'], + } + self.assertEquals(test_lcp.grade_answers(test_answers).get_correctness('1_2_1'), 'correct') + self.assertEquals(test_lcp.grade_answers(test_answers).get_correctness('1_3_1'), 'incorrect') + self.assertEquals(test_lcp.grade_answers(test_answers).get_correctness('1_4_1'), 'correct') + #----------------------------------------------------------------------------- # Grading tests diff --git a/common/lib/xmodule/tests/test_files/choiceresponse_checkbox.xml b/common/lib/xmodule/tests/test_files/choiceresponse_checkbox.xml new file mode 100644 index 0000000000..c087266d04 --- /dev/null +++ b/common/lib/xmodule/tests/test_files/choiceresponse_checkbox.xml @@ -0,0 +1,59 @@ + + + + + This is foil One. + + + This is foil Two. + + + This is foil Three. + + + This is foil Four. + + + This is foil Five. + + + + + + + This is foil One. + + + This is foil Two. + + + This is foil Three. + + + This is foil Four. + + + This is foil Five. + + + + + + + This is foil One. + + + This is foil Two. + + + This is foil Three. + + + This is foil Four. + + + This is foil Five. + + + + diff --git a/common/lib/xmodule/tests/test_files/choiceresponse_radio.xml b/common/lib/xmodule/tests/test_files/choiceresponse_radio.xml new file mode 100644 index 0000000000..a85d663b2b --- /dev/null +++ b/common/lib/xmodule/tests/test_files/choiceresponse_radio.xml @@ -0,0 +1,40 @@ + + + + + This is foil One. + + + This is foil Two. + + + This is foil Three. + + + This is foil Four. + + + This is foil Five. + + + + + + + This is foil One. + + + This is foil Two. + + + This is foil Three. + + + This is foil Four. + + + This is foil Five. + + + +