New tests for open ended module
This commit is contained in:
73
common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
Normal file
73
common/lib/xmodule/xmodule/tests/test_combined_open_ended.py
Normal file
@@ -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("<prompt>This is a question prompt</prompt>")
|
||||
rubric = '''<rubric><rubric>
|
||||
<category>
|
||||
<description>Response Quality</description>
|
||||
<option>The response is not a satisfactory answer to the question. It either fails to address the question or does so in a limited way, with no evidence of higher-order thinking.</option>
|
||||
</category>
|
||||
</rubric></rubric>'''
|
||||
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):
|
||||
@@ -10,8 +10,16 @@ from . import test_system
|
||||
|
||||
class SelfAssessmentTest(unittest.TestCase):
|
||||
|
||||
definition = {'rubric': 'A rubric',
|
||||
'prompt': 'Who?',
|
||||
rubric = '''<rubric><rubric>
|
||||
<category>
|
||||
<description>Response Quality</description>
|
||||
<option>The response is not a satisfactory answer to the question. It either fails to address the question or does so in a limited way, with no evidence of higher-order thinking.</option>
|
||||
</category>
|
||||
</rubric></rubric>'''
|
||||
|
||||
prompt = etree.XML("<prompt>This is sample prompt text.</prompt>")
|
||||
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 = '''<rubric><rubric>
|
||||
<category>
|
||||
<description>Response Quality</description>
|
||||
<option>The response is not a satisfactory answer to the question. It either fails to address the question or does so in a limited way, with no evidence of higher-order thinking.</option>
|
||||
</category>
|
||||
</rubric></rubric>'''
|
||||
|
||||
prompt = etree.XML("<prompt>Text</prompt>")
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user