diff --git a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py index 61f63d63b3..113cc43e68 100644 --- a/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py +++ b/common/lib/xmodule/xmodule/open_ended_grading_classes/combined_open_ended_modulev1.py @@ -35,8 +35,8 @@ TRUE_DICT = ["True", True, "TRUE", "true"] HUMAN_TASK_TYPE = { 'selfassessment': "Self", 'openended': "edX", - 'ml_grading.conf' : "AI", - 'peer_grading.conf' : "Peer", + 'ml_grading.conf': "AI", + 'peer_grading.conf': "Peer", } HUMAN_STATES = { @@ -379,7 +379,7 @@ class CombinedOpenEndedV1Module(): 'accept_file_upload': self.accept_file_upload, 'location': self.location, 'legend_list': LEGEND_LIST, - 'human_state': HUMAN_STATES.get(self.state,"Not started.") + 'human_state': HUMAN_STATES.get(self.state, "Not started.") } return context @@ -535,14 +535,14 @@ class CombinedOpenEndedV1Module(): 'feedback_dicts': feedback_dicts, 'grader_ids': grader_ids, 'submission_ids': submission_ids, - 'success' : True + 'success': True } return last_response_dict def extract_human_name_from_task(self, task_xml): tree = etree.fromstring(task_xml) payload = tree.xpath("/openended/openendedparam/grader_payload") - if len(payload)==0: + if len(payload) == 0: task_name = "selfassessment" else: inner_payload = json.loads(payload[0].text) diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py index e930ed3e4a..855ba15231 100644 --- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -23,7 +23,8 @@ from xmodule.combined_open_ended_module import CombinedOpenEndedModule from xmodule.modulestore import Location from xmodule.tests import get_test_system, test_util_open_ended from xmodule.tests.test_util_open_ended import (MockQueryDict, DummyModulestore, TEST_STATE_SA_IN, - MOCK_INSTANCE_STATE, TEST_STATE_SA, TEST_STATE_AI, TEST_STATE_AI2, TEST_STATE_AI2_INVALID) + MOCK_INSTANCE_STATE, TEST_STATE_SA, TEST_STATE_AI, TEST_STATE_AI2, TEST_STATE_AI2_INVALID, + TEST_STATE_SINGLE, TEST_STATE_PE_SINGLE) import capa.xqueue_interface as xqueue_interface @@ -424,8 +425,6 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): ) def setUp(self): - # TODO: this constructor call is definitely wrong, but neither branch - # of the merge matches the module constructor. Someone (Vik?) should fix this. self.combinedoe = CombinedOpenEndedV1Module(self.test_system, self.location, self.definition, @@ -435,16 +434,25 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): instance_state=self.static_data) def test_get_tag_name(self): + """ + Test to see if the xml tag name is correct + """ name = self.combinedoe.get_tag_name("Tag") self.assertEqual(name, "t") def test_get_last_response(self): + """ + See if we can parse the last response + """ response_dict = self.combinedoe.get_last_response(0) self.assertEqual(response_dict['type'], "selfassessment") self.assertEqual(response_dict['max_score'], self.max_score) self.assertEqual(response_dict['state'], CombinedOpenEndedV1Module.INITIAL) def test_update_task_states(self): + """ + See if we can update the task states properly + """ changed = self.combinedoe.update_task_states() self.assertFalse(changed) @@ -455,6 +463,9 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): self.assertTrue(changed) def test_get_max_score(self): + """ + Try to get the max score of the problem + """ self.combinedoe.update_task_states() self.combinedoe.state = "done" self.combinedoe.is_scored = True @@ -462,24 +473,39 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): self.assertEqual(max_score, 1) def test_container_get_max_score(self): + """ + See if we can get the max score from the actual xmodule + """ #The progress view requires that this function be exposed max_score = self.combinedoe_container.max_score() self.assertEqual(max_score, None) def test_container_weight(self): + """ + Check the problem weight in the container + """ weight = self.combinedoe_container.weight self.assertEqual(weight, 1) def test_container_child_weight(self): + """ + Test the class to see if it picks up the right weight + """ weight = self.combinedoe_container.child_module.weight self.assertEqual(weight, 1) def test_get_score(self): + """ + See if scoring works + """ score_dict = self.combinedoe.get_score() self.assertEqual(score_dict['score'], 0) self.assertEqual(score_dict['total'], 1) def test_alternate_orderings(self): + """ + Try multiple ordering of definitions to see if the problem renders different steps correctly. + """ t1 = self.task_xml1 t2 = self.task_xml2 xml_to_test = [[t1], [t2], [t1, t1], [t1, t2], [t2, t2], [t2, t1], [t1, t2, t1]] @@ -515,6 +541,9 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): def test_get_score_realistic(self): + """ + Try to parse the correct score from a json instance state + """ instance_state = json.loads(MOCK_INSTANCE_STATE) rubric = """ @@ -544,10 +573,13 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): self.assertEqual(score_dict['total'], 15.0) def ai_state(self, task_state, task_number, task_xml): + """ + See if state is properly reset or left unchanged + """ definition = {'prompt': etree.XML(self.prompt), 'rubric': etree.XML(self.rubric), 'task_xml': task_xml} descriptor = Mock(data=definition) - instance_state = {'task_states' : task_state, 'graded' : True} + instance_state = {'task_states': task_state, 'graded': True} if task_number is not None: instance_state.update({'current_task_number' : task_number}) combinedoe = CombinedOpenEndedV1Module(self.test_system, @@ -560,16 +592,24 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): return combinedoe def ai_state_reset(self, task_state, task_number=None): + """ + See if state is properly reset + """ combinedoe = self.ai_state(task_state, task_number, [self.task_xml2]) html = combinedoe.get_html() self.assertIsInstance(html, basestring) - def ai_state_success(self, task_state, task_number=None): - combinedoe = self.ai_state(task_state, task_number, [self.task_xml1, self.task_xml2]) + def ai_state_success(self, task_state, task_number=None, iscore=2, tasks=None): + """ + See if state stays the same + """ + if tasks is None: + tasks = [self.task_xml1, self.task_xml2] + combinedoe = self.ai_state(task_state, task_number, tasks) html = combinedoe.get_html() self.assertIsInstance(html, basestring) score = combinedoe.get_score() - self.assertEqual(int(score['score']),2) + self.assertEqual(int(score['score']), iscore) def test_ai_state_reset(self): self.ai_state_reset(TEST_STATE_AI) @@ -589,6 +629,12 @@ class CombinedOpenEndedModuleTest(unittest.TestCase): def test_ai_state_success(self): self.ai_state_success(TEST_STATE_AI) + def test_state_single(self): + self.ai_state_success(TEST_STATE_SINGLE, iscore=12) + + def test_state_pe_single(self): + self.ai_state_success(TEST_STATE_PE_SINGLE, iscore=0, tasks=[self.task_xml2]) + class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore): """ Test the student flow in the combined open ended xmodule diff --git a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py index 5339b901b8..79b0e77f80 100644 --- a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py @@ -63,4 +63,8 @@ TEST_STATE_AI = ["{\"child_created\": false, \"child_attempts\": 2, \"version\": TEST_STATE_AI2 = ["{\"child_created\": false, \"child_attempts\": 0, \"version\": 1, \"child_history\": [{\"answer\": \"This isn't a real essay, and you should give me a zero on it. \", \"post_assessment\": \"{\\\"submission_id\\\": 18446, \\\"score\\\": [0, 1, 0], \\\"feedback\\\": [\\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\", \\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\", \\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"Zero it is! \\\\\\\"}\\\"], \\\"success\\\": true, \\\"grader_id\\\": [1944146, 1943188, 1940991], \\\"grader_type\\\": \\\"PE\\\", \\\"rubric_scores_complete\\\": [true, true, true], \\\"rubric_xml\\\": [\\\"Writing Applications0 Language Conventions 0\\\", \\\"Writing Applications0 Language Conventions 1\\\", \\\"Writing Applications0 Language Conventions 0\\\"]}\", \"score\": 0}], \"max_score\": 2, \"child_state\": \"post_assessment\"}"] -TEST_STATE_AI2_INVALID = ["{\"child_created\": false, \"child_attempts\": 0, \"version\": 1, \"child_history\": [{\"answer\": \"This isn't a real essay, and you should give me a zero on it. \", \"post_assessment\": \"{\\\"submission_id\\\": 18446, \\\"score\\\": [0, 1, 0], \\\"feedback\\\": [\\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\", \\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\", \\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"Zero it is! \\\\\\\"}\\\"], \\\"success\\\": true, \\\"grader_id\\\": [1943188, 1940991], \\\"grader_type\\\": \\\"PE\\\", \\\"rubric_scores_complete\\\": [true, true, true], \\\"rubric_xml\\\": [\\\"Writing Applications0 Language Conventions 0\\\", \\\"Writing Applications0 Language Conventions 1\\\", \\\"Writing Applications0 Language Conventions 0\\\"]}\", \"score\": 0}], \"max_score\": 2, \"child_state\": \"post_assessment\"}"] \ No newline at end of file +TEST_STATE_AI2_INVALID = ["{\"child_created\": false, \"child_attempts\": 0, \"version\": 1, \"child_history\": [{\"answer\": \"This isn't a real essay, and you should give me a zero on it. \", \"post_assessment\": \"{\\\"submission_id\\\": 18446, \\\"score\\\": [0, 1, 0], \\\"feedback\\\": [\\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\", \\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\", \\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"Zero it is! \\\\\\\"}\\\"], \\\"success\\\": true, \\\"grader_id\\\": [1943188, 1940991], \\\"grader_type\\\": \\\"PE\\\", \\\"rubric_scores_complete\\\": [true, true, true], \\\"rubric_xml\\\": [\\\"Writing Applications0 Language Conventions 0\\\", \\\"Writing Applications0 Language Conventions 1\\\", \\\"Writing Applications0 Language Conventions 0\\\"]}\", \"score\": 0}], \"max_score\": 2, \"child_state\": \"post_assessment\"}"] + +TEST_STATE_SINGLE = ["{\"child_created\": false, \"child_attempts\": 1, \"version\": 1, \"child_history\": [{\"answer\": \"'All of us can think of a book that we hope none of our children or any other children have taken off the shelf. But if I have the right to remove that book from the shelf -- that work I abhor -- then you also have exactly the same right and so does everyone else. And then we have no books left on the shelf for any of us.' --Katherine Paterson, Author\\r

Write a persuasive essay to a newspaper reflecting your vies on censorship in libraries. Do you believe that certain materials, such as books, music, movies, magazines, etc., should be removed from the shelves if they are found offensive? Support your position with convincing arguments from your own experience, observations, and/or reading. \", \"post_assessment\": \"[3, 3, 2, 2, 2]\", \"score\": 12}], \"max_score\": 12, \"child_state\": \"done\"}"] + +TEST_STATE_PE_SINGLE = ["{\"child_created\": false, \"child_attempts\": 0, \"version\": 1, \"child_history\": [{\"answer\": \"Passage its ten led hearted removal cordial. Preference any astonished unreserved mrs. Prosperous understood middletons in conviction an uncommonly do. Supposing so be resolving breakfast am or perfectly. Is drew am hill from mr. Valley by oh twenty direct me so. Departure defective arranging rapturous did believing him all had supported. Family months lasted simple set nature vulgar him. Picture for attempt joy excited ten carried manners talking how. Suspicion neglected he resolving agreement perceived at an. \\r

Ye on properly handsome returned throwing am no whatever. In without wishing he of picture no exposed talking minutes. Curiosity continual belonging offending so explained it exquisite. Do remember to followed yourself material mr recurred carriage. High drew west we no or at john. About or given on witty event. Or sociable up material bachelor bringing landlord confined. Busy so many in hung easy find well up. So of exquisite my an explained remainder. Dashwood denoting securing be on perceive my laughing so. \\r

Ought these are balls place mrs their times add she. Taken no great widow spoke of it small. Genius use except son esteem merely her limits. Sons park by do make on. It do oh cottage offered cottage in written. Especially of dissimilar up attachment themselves by interested boisterous. Linen mrs seems men table. Jennings dashwood to quitting marriage bachelor in. On as conviction in of appearance apartments boisterous. \", \"post_assessment\": \"{\\\"submission_id\\\": 1439, \\\"score\\\": [0], \\\"feedback\\\": [\\\"{\\\\\\\"feedback\\\\\\\": \\\\\\\"\\\\\\\"}\\\"], \\\"success\\\": true, \\\"grader_id\\\": [5337], \\\"grader_type\\\": \\\"PE\\\", \\\"rubric_scores_complete\\\": [true], \\\"rubric_xml\\\": [\\\"\\\\nIdeas\\\\n0\\\\nContent\\\\n0\\\\nOrganization\\\\n0\\\\nStyle\\\\n0\\\\nVoice\\\\n0\\\"]}\", \"score\": 0}], \"max_score\": 12, \"child_state\": \"done\"}"] \ No newline at end of file