def test_hide_from_toc(self): course_key = SampleCourseFactory.create().id course_usage_key = self.store.make_course_usage_key(course_key) # hide chapter_x from TOC chapter_x_key = course_key.make_usage_key('chapter', 'chapter_x') chapter_x = self.store.get_item(chapter_x_key) chapter_x.hide_from_toc = True self.store.update_item(chapter_x, ModuleStoreEnum.UserID.test) block_structure = BlockStructureFactory.create_from_modulestore( course_usage_key, self.store) # collect phase BlockDepthTransformer.collect(block_structure) BlockNavigationTransformer.collect(block_structure) block_structure._collect_requested_xblock_fields() self.assertIn(chapter_x_key, block_structure) # transform phase BlockDepthTransformer().transform(usage_info=None, block_structure=block_structure) BlockNavigationTransformer(0).transform( usage_info=None, block_structure=block_structure) block_structure._prune_unreachable() self.assertIn(chapter_x_key, block_structure) course_descendants = block_structure.get_transformer_block_field( course_usage_key, BlockNavigationTransformer, BlockNavigationTransformer.BLOCK_NAVIGATION, ) # chapter_y and its descendants should be included for block_key in [ course_key.make_usage_key('chapter', 'chapter_y'), course_key.make_usage_key('sequential', 'sequential_y1'), course_key.make_usage_key('vertical', 'vertical_y1a'), course_key.make_usage_key('problem', 'problem_y1a_1'), ]: self.assertIn(six.text_type(block_key), course_descendants) # chapter_x and its descendants should not be included for block_key in [ chapter_x_key, course_key.make_usage_key('sequential', 'sequential_x1'), course_key.make_usage_key('vertical', 'vertical_x1a'), course_key.make_usage_key('problem', 'problem_x1a_1'), ]: self.assertNotIn(six.text_type(block_key), course_descendants)
def test_hide_from_toc(self): course_key = SampleCourseFactory.create().id course_usage_key = self.store.make_course_usage_key(course_key) # hide chapter_x from TOC chapter_x_key = course_key.make_usage_key('chapter', 'chapter_x') chapter_x = self.store.get_item(chapter_x_key) chapter_x.hide_from_toc = True self.store.update_item(chapter_x, ModuleStoreEnum.UserID.test) block_structure = BlockStructureFactory.create_from_modulestore(course_usage_key, self.store) # collect phase BlockDepthTransformer.collect(block_structure) BlockNavigationTransformer.collect(block_structure) block_structure._collect_requested_xblock_fields() self.assertIn(chapter_x_key, block_structure) # transform phase BlockDepthTransformer().transform(usage_info=None, block_structure=block_structure) BlockNavigationTransformer(0).transform(usage_info=None, block_structure=block_structure) block_structure._prune_unreachable() self.assertIn(chapter_x_key, block_structure) course_descendants = block_structure.get_transformer_block_field( course_usage_key, BlockNavigationTransformer, BlockNavigationTransformer.BLOCK_NAVIGATION, ) # chapter_y and its descendants should be included for block_key in [ course_key.make_usage_key('chapter', 'chapter_y'), course_key.make_usage_key('sequential', 'sequential_y1'), course_key.make_usage_key('vertical', 'vertical_y1a'), course_key.make_usage_key('problem', 'problem_y1a_1'), ]: self.assertIn(unicode(block_key), course_descendants) # chapter_x and its descendants should not be included for block_key in [ chapter_x_key, course_key.make_usage_key('sequential', 'sequential_x1'), course_key.make_usage_key('vertical', 'vertical_x1a'), course_key.make_usage_key('problem', 'problem_x1a_1'), ]: self.assertNotIn(unicode(block_key), course_descendants)
def test_navigation(self, depth, nav_depth, children_map, expected_nav_map): block_structure = self.create_block_structure( children_map, BlockStructureModulestoreData) BlockDepthTransformer(depth).transform(usage_info=None, block_structure=block_structure) BlockNavigationTransformer(nav_depth).transform( usage_info=None, block_structure=block_structure) block_structure._prune_unreachable() for block_key, expected_nav in enumerate(expected_nav_map): self.assertSetEqual( set(six.text_type(block) for block in expected_nav), set( block_structure.get_transformer_block_field( block_key, BlockNavigationTransformer, BlockNavigationTransformer.BLOCK_NAVIGATION, [])), )