Add a test case for an XBlock that has no student state fields, but sets a score
This commit is contained in:
@@ -78,6 +78,27 @@ class EmptyXModuleDescriptor(XModuleDescriptor): # pylint: disable=abstract-met
|
||||
module_class = EmptyXModule
|
||||
|
||||
|
||||
class GradedStatelessXBlock(XBlock):
|
||||
"""
|
||||
This XBlock exists to test grade storage for blocks that don't store
|
||||
student state in a scoped field.
|
||||
"""
|
||||
|
||||
@XBlock.json_handler
|
||||
def set_score(self, json_data, suffix): # pylint: disable=unused-argument
|
||||
"""
|
||||
Set the score for this testing XBlock.
|
||||
"""
|
||||
self.runtime.publish(
|
||||
self,
|
||||
'grade',
|
||||
{
|
||||
'value': json_data['grade'],
|
||||
'max_value': 1
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
@ddt.ddt
|
||||
class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
@@ -335,8 +356,7 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
self.course_key = self.create_toy_course()
|
||||
self.location = self.course_key.make_usage_key('chapter', 'Overview')
|
||||
self.toy_course = modulestore().get_course(self.course_key)
|
||||
self.mock_user = UserFactory()
|
||||
self.mock_user.id = 1
|
||||
self.mock_user = UserFactory.create()
|
||||
self.request_factory = RequestFactory()
|
||||
|
||||
# Construct a mock module for the modulestore to return
|
||||
@@ -476,6 +496,33 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
'bad_dispatch',
|
||||
)
|
||||
|
||||
@XBlock.register_temp_plugin(GradedStatelessXBlock, identifier='stateless_scorer')
|
||||
def test_score_without_student_state(self):
|
||||
course = CourseFactory.create()
|
||||
block = ItemFactory.create(category='stateless_scorer', parent=course)
|
||||
|
||||
request = self.request_factory.post(
|
||||
'dummy_url',
|
||||
data=json.dumps({"grade": 0.75}),
|
||||
content_type='application/json'
|
||||
)
|
||||
request.user = self.mock_user
|
||||
|
||||
response = render.handle_xblock_callback(
|
||||
request,
|
||||
unicode(course.id),
|
||||
quote_slashes(unicode(block.scope_ids.usage_id)),
|
||||
'set_score',
|
||||
'',
|
||||
)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
student_module = StudentModule.objects.get(
|
||||
student=self.mock_user,
|
||||
module_state_key=block.scope_ids.usage_id,
|
||||
)
|
||||
self.assertEquals(student_module.grade, 0.75)
|
||||
self.assertEquals(student_module.max_grade, 1)
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_XBLOCK_VIEW_ENDPOINT': True})
|
||||
def test_xblock_view_handler(self):
|
||||
args = [
|
||||
|
||||
Reference in New Issue
Block a user