def fetch_group_usage(cls, modulestore, structure): groups_usage_dict = {} groups_usage_info = GroupConfiguration.get_content_groups_usage_info( modulestore, structure).items() groups_usage_info.extend( GroupConfiguration.get_content_groups_items_usage_info( modulestore, structure).items()) if groups_usage_info: for name, group in groups_usage_info: for module in group: view, args, kwargs = resolve(module['url']) # pylint: disable=unused-variable usage_key_string = unicode(kwargs['usage_key_string']) if groups_usage_dict.get(usage_key_string, None): groups_usage_dict[usage_key_string].append(name) else: groups_usage_dict[usage_key_string] = [name] return groups_usage_dict
def fetch_group_usage(cls, modulestore, structure): groups_usage_dict = {} partitions_info = GroupConfiguration.get_partitions_usage_info(modulestore, structure) content_group_info = GroupConfiguration.get_content_groups_items_usage_info( modulestore, structure ) for group_info in (partitions_info, content_group_info): for groups in group_info.values(): for name, group in groups.items(): for module in group: view, args, kwargs = resolve(module['url']) # pylint: disable=unused-variable usage_key_string = text_type(kwargs['usage_key_string']) if groups_usage_dict.get(usage_key_string, None): groups_usage_dict[usage_key_string].append(name) else: groups_usage_dict[usage_key_string] = [name] return groups_usage_dict
def fetch_group_usage(cls, modulestore, structure): groups_usage_dict = {} partitions_info = GroupConfiguration.get_partitions_usage_info(modulestore, structure) content_group_info = GroupConfiguration.get_content_groups_items_usage_info( modulestore, structure ) for group_info in (partitions_info, content_group_info): for groups in group_info.values(): for name, group in groups.items(): for module in group: view, args, kwargs = resolve(module['url']) # pylint: disable=unused-variable usage_key_string = unicode(kwargs['usage_key_string']) if groups_usage_dict.get(usage_key_string, None): groups_usage_dict[usage_key_string].append(name) else: groups_usage_dict[usage_key_string] = [name] return groups_usage_dict
def test_can_handle_multiple_partitions(self): # Create the user partitions self.course.user_partitions = [ UserPartition( id=0, name='Cohort user partition', scheme=UserPartition.get_scheme('cohort'), description='Cohorted user partition', groups=[ Group(id=0, name="Group A"), Group(id=1, name="Group B"), ], ), UserPartition( id=1, name='Random user partition', scheme=UserPartition.get_scheme('random'), description='Random user partition', groups=[ Group(id=0, name="Group A"), Group(id=1, name="Group B"), ], ), ] self.store.update_item(self.course, ModuleStoreEnum.UserID.test) # Assign group access rules for multiple partitions, one of which is a cohorted partition __, problem = self._create_problem_with_content_group(0, 1) problem.group_access = { 0: [0], 1: [1], } self.store.update_item(problem, ModuleStoreEnum.UserID.test) # This used to cause an exception since the code assumed that # only one partition would be available. actual = GroupConfiguration.get_content_groups_usage_info( self.store, self.course) self.assertEqual(actual.keys(), [0]) actual = GroupConfiguration.get_content_groups_items_usage_info( self.store, self.course) self.assertEqual(actual.keys(), [0])
def test_can_handle_multiple_partitions(self): # Create the user partitions self.course.user_partitions = [ UserPartition( id=0, name='Cohort user partition', scheme=UserPartition.get_scheme('cohort'), description='Cohorted user partition', groups=[ Group(id=0, name="Group A"), Group(id=1, name="Group B"), ], ), UserPartition( id=1, name='Random user partition', scheme=UserPartition.get_scheme('random'), description='Random user partition', groups=[ Group(id=0, name="Group A"), Group(id=1, name="Group B"), ], ), ] self.store.update_item(self.course, ModuleStoreEnum.UserID.test) # Assign group access rules for multiple partitions, one of which is a cohorted partition __, problem = self._create_problem_with_content_group(0, 1) problem.group_access = { 0: [0], 1: [1], } self.store.update_item(problem, ModuleStoreEnum.UserID.test) # This used to cause an exception since the code assumed that # only one partition would be available. actual = GroupConfiguration.get_content_groups_usage_info(self.store, self.course) self.assertEqual(actual.keys(), [0]) actual = GroupConfiguration.get_content_groups_items_usage_info(self.store, self.course) self.assertEqual(actual.keys(), [0])
def test_can_handle_duplicate_group_ids(self): # Create the user partitions self.course.user_partitions = [ UserPartition( id=0, name='Cohort user partition 1', scheme=UserPartition.get_scheme('cohort'), description='Cohorted user partition', groups=[ Group(id=2, name="Group 1A"), Group(id=3, name="Group 1B"), ], ), UserPartition( id=1, name='Cohort user partition 2', scheme=UserPartition.get_scheme('cohort'), description='Random user partition', groups=[ Group(id=2, name="Group 2A"), Group(id=3, name="Group 2B"), ], ), ] self.store.update_item(self.course, ModuleStoreEnum.UserID.test) # Assign group access rules for multiple partitions, one of which is a cohorted partition self._create_problem_with_content_group(0, 2, name_suffix='0') self._create_problem_with_content_group(1, 3, name_suffix='1') # This used to cause an exception since the code assumed that # only one partition would be available. actual = GroupConfiguration.get_partitions_usage_info(self.store, self.course) self.assertEqual(actual.keys(), [0, 1]) self.assertEqual(actual[0].keys(), [2]) self.assertEqual(actual[1].keys(), [3]) actual = GroupConfiguration.get_content_groups_items_usage_info(self.store, self.course) self.assertEqual(actual.keys(), [0, 1]) self.assertEqual(actual[0].keys(), [2]) self.assertEqual(actual[1].keys(), [3])