diff --git a/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py b/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py index f20e76c40a..ffef8e1e15 100644 --- a/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py +++ b/lms/djangoapps/course_api/blocks/transformers/tests/test_student_view.py @@ -1,9 +1,9 @@ """ 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( diff --git a/openedx/core/djangoapps/content/block_structure/block_structure.py b/openedx/core/djangoapps/content/block_structure/block_structure.py index 04a823c442..ff14e62f4e 100644 --- a/openedx/core/djangoapps/content/block_structure/block_structure.py +++ b/openedx/core/djangoapps/content/block_structure/block_structure.py @@ -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): """