Commit ae15e69a by Jillian Vogel

Fixes bug with Course Blocks API student_view_data parameter

Prior to this change, providing any student_view_data querystring would result
in student_view_data returned for all XBlock types.

Updates Course Blocks API tests to verify.
parent ab011314
"""
Tests for StudentViewTransformer.
"""
import ddt
# pylint: disable=protected-access
from openedx.core.djangoapps.content.block_structure.factory import BlockStructureFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import ToyCourseFactory
......@@ -11,6 +11,7 @@ from xmodule.modulestore.tests.factories import ToyCourseFactory
from ..student_view import StudentViewTransformer
@ddt.ddt
class TestStudentViewTransformer(ModuleStoreTestCase):
"""
Test proper behavior for StudentViewTransformer
......@@ -21,20 +22,27 @@ class TestStudentViewTransformer(ModuleStoreTestCase):
self.course_usage_key = self.store.make_course_usage_key(self.course_key)
self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store)
def test_transform(self):
@ddt.data(
'video', 'html', ['video', 'html'], [],
)
def test_transform(self, requested_student_view_data):
# collect phase
StudentViewTransformer.collect(self.block_structure)
self.block_structure._collect_requested_xblock_fields()
# transform phase
StudentViewTransformer('video').transform(usage_info=None, block_structure=self.block_structure)
StudentViewTransformer(requested_student_view_data).transform(
usage_info=None,
block_structure=self.block_structure,
)
# verify video data
# verify video data returned iff requested
video_block_key = self.course_key.make_usage_key('video', 'sample_video')
self.assertIsNotNone(
self.assertEqual(
self.block_structure.get_transformer_block_field(
video_block_key, StudentViewTransformer, StudentViewTransformer.STUDENT_VIEW_DATA,
)
) is not None,
'video' in requested_student_view_data
)
self.assertFalse(
self.block_structure.get_transformer_block_field(
......@@ -42,12 +50,13 @@ class TestStudentViewTransformer(ModuleStoreTestCase):
)
)
# verify html data
# verify html data returned iff requested
html_block_key = self.course_key.make_usage_key('html', 'toyhtml')
self.assertIsNotNone(
self.assertEqual(
self.block_structure.get_transformer_block_field(
html_block_key, StudentViewTransformer, StudentViewTransformer.STUDENT_VIEW_DATA,
)
) is not None,
'html' in requested_student_view_data
)
self.assertTrue(
self.block_structure.get_transformer_block_field(
......
......@@ -312,7 +312,7 @@ class FieldData(object):
if self._is_own_field(field_name):
return super(FieldData, self).__delattr__(field_name)
else:
delattr(self.fields, field_name)
del self.fields[field_name]
def _is_own_field(self, field_name):
"""
......
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