本文整理汇总了Python中openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme.get_group_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python RandomUserPartitionScheme.get_group_for_user方法的具体用法?Python RandomUserPartitionScheme.get_group_for_user怎么用?Python RandomUserPartitionScheme.get_group_for_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme
的用法示例。
在下文中一共展示了RandomUserPartitionScheme.get_group_for_user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_group_for_user
# 需要导入模块: from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme [as 别名]
# 或者: from openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme import get_group_for_user [as 别名]
def test_get_group_for_user(self):
# get a group assigned to the user
group1_id = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
# make sure we get the same group back out every time
for __ in range(10):
group2_id = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
self.assertEqual(group1_id, group2_id)
示例2: test_empty_partition
# 需要导入模块: from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme [as 别名]
# 或者: from openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme import get_group_for_user [as 别名]
def test_empty_partition(self):
empty_partition = UserPartition(
self.TEST_ID,
'Test Partition',
'for testing purposes',
[],
scheme=RandomUserPartitionScheme
)
# get a group assigned to the user
with self.assertRaisesRegexp(UserPartitionError, "Cannot assign user to an empty user partition"):
RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, empty_partition)
示例3: test_user_in_deleted_group
# 需要导入模块: from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme [as 别名]
# 或者: from openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme import get_group_for_user [as 别名]
def test_user_in_deleted_group(self):
# get a group assigned to the user - should be group 0 or 1
old_group = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
self.assertIn(old_group.id, [0, 1])
# Change the group definitions! No more group 0 or 1
groups = [Group(3, 'Group 3'), Group(4, 'Group 4')]
user_partition = UserPartition(self.TEST_ID, 'Test Partition', 'for testing purposes', groups)
# Now, get a new group using the same call - should be 3 or 4
new_group = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, user_partition)
self.assertIn(new_group.id, [3, 4])
# We should get the same group over multiple calls
new_group_2 = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, user_partition)
self.assertEqual(new_group, new_group_2)
示例4: test_get_group_for_user_with_assign
# 需要导入模块: from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme [as 别名]
# 或者: from openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme import get_group_for_user [as 别名]
def test_get_group_for_user_with_assign(self):
"""
Make sure get_group_for_user returns None if no group is already
assigned to a user instead of assigning/creating a group automatically
"""
# We should not get any group because assign is False which will
# protect us from automatically creating a group for user
group = RandomUserPartitionScheme.get_group_for_user(
self.MOCK_COURSE_ID, self.user, self.user_partition, assign=False
)
self.assertIsNone(group)
# We should get a group automatically assigned to user
group = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
self.assertIsNotNone(group)
示例5: test_change_group_name
# 需要导入模块: from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme [as 别名]
# 或者: from openedx.core.djangoapps.user_api.partition_schemes.RandomUserPartitionScheme import get_group_for_user [as 别名]
def test_change_group_name(self):
# Changing the name of the group shouldn't affect anything
# get a group assigned to the user - should be group 0 or 1
old_group = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
self.assertIn(old_group.id, [0, 1])
# Change the group names
groups = [Group(0, 'Group 0'), Group(1, 'Group 1')]
user_partition = UserPartition(
self.TEST_ID,
'Test Partition',
'for testing purposes',
groups,
scheme=RandomUserPartitionScheme
)
# Now, get a new group using the same call
new_group = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, user_partition)
self.assertEqual(old_group.id, new_group.id)