From f9e97cb935e943baed19f1192e6dc371952245eb Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Thu, 9 May 2013 10:05:48 -0400 Subject: [PATCH] Add test for proper saving --- .../xmodule/tests/test_combined_open_ended.py | 5 ++++ .../xmodule/tests/test_peer_grading.py | 23 ++++++++++++++++++- .../xmodule/tests/test_util_open_ended.py | 8 +++---- .../peergrading/PeerGradingScored.xml | 2 +- 4 files changed, 32 insertions(+), 6 deletions(-) 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 1d67e94376..48ea6e7911 100644 --- a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -496,6 +496,7 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore): self.test_system.xqueue['interface'] = Mock( send_to_queue=Mock(side_effect=[1, "queued"]) ) + self.setup_modulestore(COURSE) def test_open_ended_load_and_save(self): """ @@ -510,6 +511,10 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore): task_one_json = json.loads(module.task_states[0]) self.assertEqual(task_one_json['child_history'][0]['answer'], self.answer) + module = self.get_module_from_location(self.problem_location, COURSE) + task_one_json = json.loads(module.task_states[0]) + self.assertEqual(task_one_json['child_history'][0]['answer'], self.answer) + def test_open_ended_flow_reset(self): """ Test the flow of the module if we complete the self assessment step and then reset diff --git a/common/lib/xmodule/xmodule/tests/test_peer_grading.py b/common/lib/xmodule/xmodule/tests/test_peer_grading.py index 49c696f741..036ab4a85b 100644 --- a/common/lib/xmodule/xmodule/tests/test_peer_grading.py +++ b/common/lib/xmodule/xmodule/tests/test_peer_grading.py @@ -40,6 +40,7 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore): """ self.test_system = test_system() self.test_system.open_ended_grading_interface = None + self.setup_modulestore(COURSE) self.peer_grading = self.get_module_from_location(self.problem_location, COURSE) def test_module_closed(self): @@ -129,4 +130,24 @@ class PeerGradingModuleTest(unittest.TestCase, DummyModulestore): Get the instance state dict @return: """ - self.peer_grading.get_instance_state() \ No newline at end of file + self.peer_grading.get_instance_state() + +class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore): + """ + Test peer grading xmodule at the unit level. More detailed tests are difficult, as the module relies on an + external grading service. + """ + problem_location = Location(["i4x", "edX", "open_ended", "peergrading", + "PeerGradingScored"]) + def setUp(self): + """ + Create a peer grading module from a test system + @return: + """ + self.test_system = test_system() + self.test_system.open_ended_grading_interface = None + self.setup_modulestore(COURSE) + + def test_metadata_load(self): + peer_grading = self.get_module_from_location(self.problem_location, COURSE) + self.assertEqual(peer_grading.closed(), False) \ No newline at end of file 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 f269a8a002..3737586232 100644 --- a/common/lib/xmodule/xmodule/tests/test_util_open_ended.py +++ b/common/lib/xmodule/xmodule/tests/test_util_open_ended.py @@ -38,12 +38,12 @@ class DummyModulestore(object): """ test_system = test_system() + def setup_modulestore(self, name): + self.modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name]) + def get_course(self, name): """Get a test course by directory name. If there's more than one, error.""" - - modulestore = XMLModuleStore(DATA_DIR, course_dirs=[name]) - courses = modulestore.get_courses() - self.modulestore = modulestore + courses = self.modulestore.get_courses() return courses[0] def get_module_from_location(self, location, course): diff --git a/common/test/data/open_ended/peergrading/PeerGradingScored.xml b/common/test/data/open_ended/peergrading/PeerGradingScored.xml index b2380b1e1b..6398a9b4c5 100644 --- a/common/test/data/open_ended/peergrading/PeerGradingScored.xml +++ b/common/test/data/open_ended/peergrading/PeerGradingScored.xml @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file