def test_duplicated_version(self): """ Test that if a library is updated, and the content block is duplicated, the new block will use the old library version and not the new one. """ store = modulestore() self.assertEqual(len(self.library.children), 1) self.assertEqual(len(self.lc_block.children), 1) # Edit the only problem in the library: self.problem.display_name = "--changed in library--" store.update_item(self.problem, self.user.id) # Create an additional problem block in the library: ItemFactory.create( category="problem", parent_location=self.library.location, user_id=self.user.id, publish_item=False, ) # Refresh our reference to the library self.library = store.get_library(self.lib_key) # Refresh our reference to the block self.lc_block = store.get_item(self.lc_block.location) self.problem_in_course = store.get_item( self.problem_in_course.location) # The library has changed... self.assertEqual(len(self.library.children), 2) # But the block hasn't. self.assertEqual(len(self.lc_block.children), 1) self.assertEqual(self.problem_in_course.location, self.lc_block.children[0]) self.assertEqual(self.problem_in_course.display_name, self.original_display_name) # Duplicate self.lc_block: duplicate = store.get_item( _duplicate_item(self.course.location, self.lc_block.location, self.user)) # The duplicate should have identical children to the original: self.assertEqual(len(duplicate.children), 1) self.assertTrue(self.lc_block.source_library_version) self.assertEqual(self.lc_block.source_library_version, duplicate.source_library_version) problem2_in_course = store.get_item(duplicate.children[0]) self.assertEqual(problem2_in_course.display_name, self.original_display_name)
def test_persistent_overrides(self, duplicate): """ Test that when we override Scope.settings values in a course, the override values persist even when the block is refreshed with updated blocks from the library. """ new_display_name = "Modified Problem Title" new_weight = 15 self.problem_in_course.display_name = new_display_name self.problem_in_course.weight = new_weight modulestore().update_item(self.problem_in_course, self.user.id) if duplicate: # Check that this also works when the RCB is duplicated. self.lc_block = modulestore().get_item( _duplicate_item(self.course.location, self.lc_block.location, self.user)) self.problem_in_course = modulestore().get_item( self.lc_block.children[0]) else: self.problem_in_course = modulestore().get_item( self.problem_in_course.location) self.assertEqual(self.problem_in_course.display_name, new_display_name) self.assertEqual(self.problem_in_course.weight, new_weight) # Change the settings in the library version: self.problem.display_name = "X" self.problem.weight = 99 new_data_value = "<problem><p>Changed data to check that non-overriden fields *do* get updated.</p></problem>" self.problem.data = new_data_value modulestore().update_item(self.problem, self.user.id) self.lc_block = self._refresh_children(self.lc_block) self.problem_in_course = modulestore().get_item( self.problem_in_course.location) self.assertEqual(self.problem_in_course.display_name, new_display_name) self.assertEqual(self.problem_in_course.weight, new_weight) self.assertEqual(self.problem_in_course.data, new_data_value)