本文整理汇总了Python中contentstore.course_group_config.GroupConfiguration类的典型用法代码示例。如果您正苦于以下问题:Python GroupConfiguration类的具体用法?Python GroupConfiguration怎么用?Python GroupConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GroupConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_get_usage_info_when_special_characters_are_used
def test_can_get_usage_info_when_special_characters_are_used(self):
"""
Test if group configurations json updated successfully when special
characters are being used in content experiment
"""
self._add_user_partitions(count=1)
vertical, __ = self._create_content_experiment(cid=0, name_suffix='0', special_characters=u"JOSÉ ANDRÉS")
actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course, )
expected = [{
'id': 0,
'name': 'Name 0',
'scheme': 'random',
'description': 'Description 0',
'version': UserPartition.VERSION,
'groups': [
{'id': 0, 'name': 'Group A', 'version': 1},
{'id': 1, 'name': 'Group B', 'version': 1},
{'id': 2, 'name': 'Group C', 'version': 1},
],
'usage': [{
'url': '/container/{}'.format(vertical.location),
'label': u"Test Unit 0 / Test Content Experiment 0JOSÉ ANDRÉS",
'validation': None,
}],
}]
self.assertEqual(actual, expected)
示例2: test_can_use_one_configuration_in_multiple_experiments
def test_can_use_one_configuration_in_multiple_experiments(self):
"""
Test if multiple experiments are present in usage info when they use same
group configuration.
"""
self._add_user_partitions()
vertical, __ = self._create_content_experiment(cid=0, name_suffix='0')
vertical1, __ = self._create_content_experiment(cid=0, name_suffix='1')
actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course)
expected = [{
'id': 0,
'name': 'Name 0',
'scheme': 'random',
'description': 'Description 0',
'version': UserPartition.VERSION,
'groups': [
{'id': 0, 'name': 'Group A', 'version': 1},
{'id': 1, 'name': 'Group B', 'version': 1},
{'id': 2, 'name': 'Group C', 'version': 1},
],
'usage': [{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Content Experiment 0',
'validation': None,
}, {
'url': '/container/{}'.format(vertical1.location),
'label': 'Test Unit 1 / Test Content Experiment 1',
'validation': None,
}],
}]
self.assertEqual(actual, expected)
示例3: _get_user_partition
def _get_user_partition(self, scheme):
"""
Returns the first user partition with the specified scheme.
"""
for group in GroupConfiguration.get_all_user_partition_details(self.store, self.course):
if group['scheme'] == scheme:
return group
return None
示例4: test_content_group_not_used
def test_content_group_not_used(self):
"""
Test that right data structure will be created if content group is not used.
"""
self._add_user_partitions(scheme_id='cohort')
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
expected = self._get_expected_content_group(usage_for_group=[])
self.assertEqual(actual, expected)
示例5: fetch_group_usage
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
示例6: test_can_handle_duplicate_group_ids
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])
示例7: test_can_handle_multiple_partitions
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])
示例8: verify_validation_add_usage_info
def verify_validation_add_usage_info(self, expected_result, mocked_message, mocked_validation_messages):
"""
Helper method for testing validation information present after add_usage_info.
"""
self._add_user_partitions()
split_test = self._create_content_experiment(cid=0, name_suffix='0')[1]
validation = StudioValidation(split_test.location)
validation.add(mocked_message)
mocked_validation_messages.return_value = validation
group_configuration = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course)[0]
self.assertEqual(expected_result.to_json(), group_configuration['usage'][0]['validation'])
示例9: val_items_visibility_by_group
def val_items_visibility_by_group(self):
"""Составление таблицы видимости элементов для групп"""
with self.store.bulk_operations(self.course_key):
course = self.course
content_group_configuration = GroupConfiguration.get_or_create_content_group(self.store, course)
groups = content_group_configuration["groups"]
group_names = [g["name"] for g in groups]
head = [_("Item type"), _("Usual student")] + group_names
visibility_by_group_categories = self.visibility_by_group_categories
get_items_by_type = lambda x: [y for y in self.items if y.category == x]
# Словарь (категория - итемы)
cat_items = dict([(c, get_items_by_type(c)) for c in visibility_by_group_categories])
# Словарь id группы - название группы
group_id_dict = dict([(g["id"], g["name"]) for g in groups])
conf_id = content_group_configuration["id"]
group_visible_strs = []
for cat in visibility_by_group_categories:
items = cat_items[cat]
vis = dict((g, 0) for g in group_names)
vis["student"] = 0
for it in items:
if conf_id not in it.group_access:
for key in group_names:
vis[key] += 1
else:
ids = it.group_access[conf_id]
item_vis_for_groups = [group_id_dict[i] for i in ids]
for group in item_vis_for_groups:
vis[group] += 1
if not it.visible_to_staff_only:
vis["student"] += 1
item_category = "{}({})".format(cat, len(items))
stud_vis_for_cat = str(vis["student"])
cat_list = [item_category] + [stud_vis_for_cat] + [str(vis[gn]) for gn in group_names]
cat_str = cat_list
group_visible_strs.append(cat_str)
return Report(name=self.scenarios_names["items_visibility_by_group"],
head=head,
body=group_visible_strs,
warnings=[]
)
示例10: test_can_get_correct_usage_info_for_content_groups
def test_can_get_correct_usage_info_for_content_groups(self):
"""
Test if content group json updated successfully with usage information.
"""
self._add_user_partitions(count=1, scheme_id='cohort')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
expected = self._get_expected_content_group(usage_for_group=[
{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Problem 0'
}
])
self.assertEqual(actual, expected)
示例11: test_can_get_correct_usage_info
def test_can_get_correct_usage_info(self):
"""
Test if group configurations json updated successfully with usage information.
"""
self._add_user_partitions(count=2)
vertical, __ = self._create_content_experiment(cid=0, name_suffix='0')
self._create_content_experiment(name_suffix='1')
actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course)
expected = [{
'id': 0,
'name': 'Name 0',
'scheme': 'random',
'description': 'Description 0',
'version': UserPartition.VERSION,
'groups': [
{'id': 0, 'name': 'Group A', 'version': 1},
{'id': 1, 'name': 'Group B', 'version': 1},
{'id': 2, 'name': 'Group C', 'version': 1},
],
'usage': [{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Content Experiment 0',
'validation': None,
}],
'parameters': {},
'active': True,
}, {
'id': 1,
'name': 'Name 1',
'scheme': 'random',
'description': 'Description 1',
'version': UserPartition.VERSION,
'groups': [
{'id': 0, 'name': 'Group A', 'version': 1},
{'id': 1, 'name': 'Group B', 'version': 1},
{'id': 2, 'name': 'Group C', 'version': 1},
],
'usage': [],
'parameters': {},
'active': True,
}]
self.assertEqual(actual, expected)
示例12: test_can_handle_without_parent
def test_can_handle_without_parent(self):
"""
Test if it possible to handle case when split_test has no parent.
"""
self._add_user_partitions()
# Create split test without parent.
with modulestore().branch_setting(ModuleStoreEnum.Branch.published_only):
orphan = modulestore().create_item(
ModuleStoreEnum.UserID.test,
self.course.id, 'split_test',
)
orphan.user_partition_id = 0
orphan.display_name = 'Test Content Experiment'
modulestore().update_item(orphan, ModuleStoreEnum.UserID.test)
self.save_course()
actual = GroupConfiguration.get_content_experiment_usage_info(self.store, self.course)
self.assertEqual(actual, {0: []})
示例13: val_group
def val_group(self):
"""Проверка наличия и использования в курсе групп"""
with self.store.bulk_operations(self.course_key):
course = self.course
content_group_configuration = GroupConfiguration.get_or_create_content_group(self.store, course)
groups = content_group_configuration["groups"]
is_group_used = lambda x: bool(len(x["usage"]))
# запись для каждой группы ее использования
group_strs = [[g["name"], str(is_group_used(g))] for g in groups]
head = [_("Group name"), _("Group used")]
results = Report(name=self.scenarios_names["group"],
head=head,
body=group_strs,
warnings=[],
)
return results
示例14: test_group_configuration_not_used
def test_group_configuration_not_used(self):
"""
Test that right data structure will be created if group configuration is not used.
"""
self._add_user_partitions()
actual = GroupConfiguration.get_split_test_partitions_with_usage(self.store, self.course)
expected = [{
'id': 0,
'name': 'Name 0',
'scheme': 'random',
'description': 'Description 0',
'version': UserPartition.VERSION,
'groups': [
{'id': 0, 'name': 'Group A', 'version': 1},
{'id': 1, 'name': 'Group B', 'version': 1},
{'id': 2, 'name': 'Group C', 'version': 1},
],
'usage': [],
}]
self.assertEqual(actual, expected)
示例15: test_can_use_one_content_group_in_multiple_problems
def test_can_use_one_content_group_in_multiple_problems(self):
"""
Test if multiple problems are present in usage info when they use same
content group.
"""
self._add_user_partitions(scheme_id='cohort')
vertical, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='0')
vertical1, __ = self._create_problem_with_content_group(cid=0, group_id=1, name_suffix='1')
actual = GroupConfiguration.get_or_create_content_group(self.store, self.course)
expected = self._get_expected_content_group(usage_for_group=[
{
'url': '/container/{}'.format(vertical.location),
'label': 'Test Unit 0 / Test Problem 0'
},
{
'url': '/container/{}'.format(vertical1.location),
'label': 'Test Unit 1 / Test Problem 1'
}
])
self.assertEqual(actual, expected)