diff --git a/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py new file mode 100644 index 0000000000..12ad862a43 --- /dev/null +++ b/common/lib/xmodule/xmodule/tests/test_combined_open_ended.py @@ -0,0 +1,73 @@ +import json +from mock import Mock +import unittest + +from xmodule.openendedchild import OpenEndedChild +from xmodule.modulestore import Location +from lxml import etree + +from . import test_system + +class OpenEndedChildTest(unittest.TestCase): + location = Location(["i4x", "edX", "sa_test", "selfassessment", + "SampleQuestion"]) + + metadata = json.dumps({'attempts': '10'}) + prompt = etree.XML("This is a question prompt") + rubric = ''' + + Response Quality + + + ''' + max_score = 4 + + static_data = { + 'max_attempts': 20, + 'prompt': prompt, + 'rubric': rubric, + 'max_score': max_score, + } + definition = Mock() + descriptor = Mock() + + + def test_latest_answer_empty(self): + openendedchild = OpenEndedChild(test_system, self.location, + self.definition, self.descriptor, self.static_data, self.metadata) + answer = openendedchild.latest_answer() + self.assertEqual(answer, "") + + def test_latest_answer_nonempty(self): + metadata = json.dumps({ 'attempts': 10, + 'history': [{'answer': "Two"}, {'answer': "Three"}]}) + openendedchild = OpenEndedChild(test_system, self.location, + self.definition, self.descriptor, self.static_data, metadata) + answer = openendedchild.latest_answer() + self.assertEqual(answer, "Three") + + def test_latest_score_empty(self): + openendedchild = OpenEndedChild(test_system, self.location, + self.definition, self.descriptor, self.static_data, self.metadata) + answer = openendedchild.latest_score() + self.assertEqual(answer, None) + + + def test_latest_score_nonempty(self): + metadata = json.dumps({ 'attempts': 10, + 'history': [{'score': 3}, {'score': 2}]}) + openendedchild = OpenEndedChild(test_system, self.location, + self.definition, self.descriptor, self.static_data, metadata) + answer = openendedchild.latest_score() + self.assertEqual(answer, 2) + + + def test_new_history_entry(self): + openendedchild = OpenEndedChild(test_system, self.location, + self.definition, self.descriptor, self.static_data, self.metadata) + new_answer = "New Answer" + openendedchild.new_history_entry(new_answer) + answer = openendedchild.latest_answer() + self.assertEqual(answer, new_answer) + + #def test_record_latest_score(self): diff --git a/common/lib/xmodule/xmodule/tests/test_self_assessment.py b/common/lib/xmodule/xmodule/tests/test_self_assessment.py index 565483c586..a11facb05b 100644 --- a/common/lib/xmodule/xmodule/tests/test_self_assessment.py +++ b/common/lib/xmodule/xmodule/tests/test_self_assessment.py @@ -10,8 +10,16 @@ from . import test_system class SelfAssessmentTest(unittest.TestCase): - definition = {'rubric': 'A rubric', - 'prompt': 'Who?', + rubric = ''' + + Response Quality + + + ''' + + prompt = etree.XML("This is sample prompt text.") + definition = {'rubric': rubric, + 'prompt': prompt, 'submitmessage': 'Shall we submit now?', 'hintprompt': 'Consider this...', } @@ -23,48 +31,47 @@ class SelfAssessmentTest(unittest.TestCase): descriptor = Mock() - def test_import(self): + def setUp(self): state = json.dumps({'student_answers': ["Answer 1", "answer 2", "answer 3"], 'scores': [0, 1], 'hints': ['o hai'], 'state': SelfAssessmentModule.INITIAL, 'attempts': 2}) - rubric = ''' - - Response Quality - - - ''' - - prompt = etree.XML("Text") static_data = { 'max_attempts': 10, - 'rubric': etree.XML(rubric), - 'prompt': prompt, + 'rubric': etree.XML(self.rubric), + 'prompt': self.prompt, 'max_score': 1 } - module = SelfAssessmentModule(test_system, self.location, + self.module = SelfAssessmentModule(test_system, self.location, self.definition, self.descriptor, static_data, state, metadata=self.metadata) - self.assertEqual(module.get_score()['score'], 0) + def test_get_html(self): + html = self.module.get_html(test_system) + self.assertTrue(html.find("This is sample prompt text") != -1) + + def test_self_assessment_flow(self): + + self.assertEqual(self.module.get_score()['score'], 0) - module.save_answer({'student_answer': "I am an answer"}, test_system) - self.assertEqual(module.state, module.ASSESSING) + self.module.save_answer({'student_answer': "I am an answer"}, test_system) + self.assertEqual(self.module.state, self.module.ASSESSING) - module.save_assessment({'assessment': '0'}, test_system) - self.assertEqual(module.state, module.POST_ASSESSMENT) - module.save_hint({'hint': 'this is a hint'}, test_system) - self.assertEqual(module.state, module.DONE) + self.module.save_assessment({'assessment': '0'}, test_system) + self.assertEqual(self.module.state, self.module.POST_ASSESSMENT) + self.module.save_hint({'hint': 'this is a hint'}, test_system) + self.assertEqual(self.module.state, self.module.DONE) - d = module.reset({}) + d = self.module.reset({}) self.assertTrue(d['success']) - self.assertEqual(module.state, module.INITIAL) + self.assertEqual(self.module.state, self.module.INITIAL) # if we now assess as right, skip the REQUEST_HINT state - module.save_answer({'student_answer': 'answer 4'}, test_system) - module.save_assessment({'assessment': '1'}, test_system) - self.assertEqual(module.state, module.DONE) + self.module.save_answer({'student_answer': 'answer 4'}, test_system) + self.module.save_assessment({'assessment': '1'}, test_system) + self.assertEqual(self.module.state, self.module.DONE) +