Commit 82cf37b2 by Victor Shnayder

Merge pull request #1085 from MITx/feature/victor/fix-self-assessment

Feature/victor/fix self assessment
parents 68158b39 4b58cb95
...@@ -120,7 +120,7 @@ class @SelfAssessment ...@@ -120,7 +120,7 @@ class @SelfAssessment
if @state == 'done' if @state == 'done'
$.postWithPrefix "#{@ajax_url}/reset", {}, (response) => $.postWithPrefix "#{@ajax_url}/reset", {}, (response) =>
if response.success if response.success
@answer_area.html('') @answer_area.val('')
@rubric_wrapper.html('') @rubric_wrapper.html('')
@hint_wrapper.html('') @hint_wrapper.html('')
@message_wrapper.html('') @message_wrapper.html('')
......
...@@ -19,11 +19,12 @@ import xmodule ...@@ -19,11 +19,12 @@ import xmodule
from xmodule.x_module import ModuleSystem from xmodule.x_module import ModuleSystem
from mock import Mock from mock import Mock
i4xs = ModuleSystem( 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(),
......
...@@ -5,7 +5,7 @@ import unittest ...@@ -5,7 +5,7 @@ import unittest
from xmodule.progress import Progress from xmodule.progress import Progress
from xmodule import x_module from xmodule import x_module
from . import i4xs from . import test_system
class ProgressTest(unittest.TestCase): class ProgressTest(unittest.TestCase):
''' Test that basic Progress objects work. A Progress represents a ''' Test that basic Progress objects work. A Progress represents a
...@@ -133,6 +133,6 @@ class ModuleProgressTest(unittest.TestCase): ...@@ -133,6 +133,6 @@ class ModuleProgressTest(unittest.TestCase):
''' '''
def test_xmodule_default(self): def test_xmodule_default(self):
'''Make sure default get_progress exists, returns None''' '''Make sure default get_progress exists, returns None'''
xm = x_module.XModule(i4xs, 'a://b/c/d/e', None, {}) xm = x_module.XModule(test_system, 'a://b/c/d/e', None, {})
p = xm.get_progress() p = xm.get_progress()
self.assertEqual(p, None) self.assertEqual(p, None)
import json
from mock import Mock
import unittest
from xmodule.self_assessment_module import SelfAssessmentModule
from xmodule.modulestore import Location
from . import test_system
class SelfAssessmentTest(unittest.TestCase):
definition = {'rubric': 'A rubric',
'prompt': 'Who?',
'submitmessage': 'Shall we submit now?',
'hintprompt': 'Consider this...',
}
location = Location(["i4x", "edX", "sa_test", "selfassessment",
"SampleQuestion"])
metadata = {'attempts': '10'}
descriptor = Mock()
def test_import(self):
state = json.dumps({'student_answers': ["Answer 1", "answer 2", "answer 3"],
'scores': [0, 1],
'hints': ['o hai'],
'state': SelfAssessmentModule.ASSESSING,
'attempts': 2})
module = SelfAssessmentModule(test_system, self.location,
self.definition, self.descriptor,
state, {}, metadata=self.metadata)
self.assertEqual(module.get_score()['score'], 0)
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)
...@@ -288,8 +288,20 @@ class XModule(HTMLSnippet): ...@@ -288,8 +288,20 @@ class XModule(HTMLSnippet):
return '{}' return '{}'
def get_score(self): def get_score(self):
''' Score the student received on the problem. """
''' Score the student received on the problem, or None if there is no
score.
Returns:
dictionary
{'score': integer, from 0 to get_max_score(),
'total': get_max_score()}
NOTE (vshnayder): not sure if this was the intended return value, but
that's what it's doing now. I suspect that we really want it to just
return a number. Would need to change (at least) capa and
modx_dispatch to match if we did that.
"""
return None return None
def max_score(self): def max_score(self):
......
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