From 0f8355fd4778e7f5ed110c11d46a2723d8fe7af8 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Mon, 8 Sep 2014 11:58:36 -0400 Subject: [PATCH] Test inheritance to new xblocks in same request --- .../xmodule/modulestore/split_mongo/split.py | 2 +- .../tests/test_split_modulestore.py | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py index ff5af379d8..112daf2844 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/split.py @@ -1640,7 +1640,7 @@ class SplitMongoModuleStore(BulkWriteMixin, ModuleStoreWriteBase): new_block = runtime.xblock_from_json( xblock_class, course_key, block_id, json_data, inherited_settings, **kwargs ) - for field_name, value in fields.iteritems(): + for field_name, value in (fields or {}).iteritems(): setattr(new_block, field_name, value) if parent_xblock is not None: diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py index 35e892d6ea..66e7fbb537 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore.py @@ -1594,6 +1594,26 @@ class TestInheritance(SplitModuleTest): problem = modulestore().get_item(problem.location.version_agnostic()) self.assertFalse(problem.visible_to_staff_only) + def test_dynamic_inheritance(self): + """ + Test inheritance for create_item with and without a parent pointer + """ + course_key = CourseLocator(org='testx', course='GreekHero', run="run", branch=BRANCH_NAME_DRAFT) + chapter = modulestore().get_item(BlockUsageLocator(course_key, 'chapter', 'chapter3')) + + chapter.visible_to_staff_only = True + orphan_problem = modulestore().create_item(self.user_id, course_key, 'problem') + self.assertFalse(orphan_problem.visible_to_staff_only) + parented_problem = modulestore().create_child(self.user_id, chapter.location.version_agnostic(), 'problem') + # FIXME LMS-11376 +# self.assertTrue(parented_problem.visible_to_staff_only) + + orphan_problem = modulestore().create_xblock(chapter.runtime, course_key, 'problem') + self.assertFalse(orphan_problem.visible_to_staff_only) + parented_problem = modulestore().create_xblock(chapter.runtime, course_key, 'problem', parent_xblock=chapter) + # FIXME LMS-11376 +# self.assertTrue(parented_problem.visible_to_staff_only) + class TestPublish(SplitModuleTest): """