Commit f8e45e0a by Victor Shnayder

Add tests for old logic

parent a0a51672
...@@ -4,7 +4,7 @@ unittests for xmodule ...@@ -4,7 +4,7 @@ unittests for xmodule
Run like this: Run like this:
rake test_common/lib/xmodule rake test_common/lib/xmodule
""" """
import unittest import unittest
...@@ -23,7 +23,8 @@ test_system = ModuleSystem( ...@@ -23,7 +23,8 @@ test_system = ModuleSystem(
ajax_url='courses/course_id/modx/a_location', ajax_url='courses/course_id/modx/a_location',
track_function=Mock(), track_function=Mock(),
get_module=Mock(), get_module=Mock(),
render_template=Mock(), # "render" to just the context...
render_template=lambda template, context: str(context),
replace_urls=Mock(), replace_urls=Mock(),
user=Mock(), user=Mock(),
filestore=Mock(), filestore=Mock(),
......
...@@ -12,24 +12,44 @@ class SelfAssessmentTest(unittest.TestCase): ...@@ -12,24 +12,44 @@ class SelfAssessmentTest(unittest.TestCase):
definition = {'rubric': 'A rubric', definition = {'rubric': 'A rubric',
'prompt': 'Who?', 'prompt': 'Who?',
'submitmessage': 'Shall we submit now?', 'submitmessage': 'Shall we submit now?',
'hintprompt': 'Consider this...'} 'hintprompt': 'Consider this...',
}
location = Location(["i4x", "edX", "sa_test", "selfassessment", location = Location(["i4x", "edX", "sa_test", "selfassessment",
"SampleQuestion"]) "SampleQuestion"])
metadata = {} metadata = {'attempts': '10'}
descriptor = Mock() descriptor = Mock()
def test_import(self): def test_import(self):
state = json.dumps({'student_answers': [], state = json.dumps({'student_answers': ["Answer 1", "answer 2", "answer 3"],
'scores': [], 'scores': [0, 1],
'hints': [], 'hints': ['o hai'],
'state': 'initial', 'state': SelfAssessmentModule.ASSESSING,
'attempts': 0}) 'attempts': 2})
module = SelfAssessmentModule(test_system, self.location, module = SelfAssessmentModule(test_system, self.location,
self.definition, self.descriptor, self.definition, self.descriptor,
state, {}) state, {}, metadata=self.metadata)
self.assertEqual(module.get_score(), 0) self.assertEqual(module.get_score(), 1)
self.assertTrue('answer 3' in module.get_html())
self.assertFalse('answer 2' in module.get_html())
module.save_assessment({'assessment': '0'})
self.assertEqual(module.state, module.REQUEST_HINT)
module.save_hint({'hint': 'hint for ans 3'})
self.assertEqual(module.state, module.DONE)
d = module.reset({})
self.assertTrue(d['success'])
self.assertEqual(module.state, module.INITIAL)
# if we now assess as right, skip the REQUEST_HINT state
module.save_answer({'student_answer': 'answer 4'})
module.save_assessment({'assessment': '1'})
self.assertEqual(module.state, module.DONE)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment