Get students experiments, groups, and cohorts
TNL-498
This commit is contained in:
@@ -15,15 +15,16 @@ class RandomUserPartitionScheme(object):
|
||||
RANDOM = random.Random()
|
||||
|
||||
@classmethod
|
||||
def get_group_for_user(cls, course_id, user, user_partition, track_function=None):
|
||||
def get_group_for_user(cls, course_id, user, user_partition, assign=True, track_function=None):
|
||||
"""
|
||||
Returns the group from the specified user position to which the user is assigned.
|
||||
If the user has not yet been assigned, a group will be randomly chosen for them.
|
||||
If the user has not yet been assigned, a group will be randomly chosen for them if assign flag is True.
|
||||
"""
|
||||
partition_key = cls._key_for_partition(user_partition)
|
||||
group_id = course_tag_api.get_course_tag(user, course_id, partition_key)
|
||||
group = user_partition.get_group(int(group_id)) if not group_id is None else None
|
||||
if group is None:
|
||||
|
||||
if group is None and assign:
|
||||
if not user_partition.groups:
|
||||
raise UserPartitionError('Cannot assign user to an empty user partition')
|
||||
|
||||
|
||||
@@ -58,6 +58,24 @@ class TestRandomUserPartitionScheme(PartitionTestCase):
|
||||
group2_id = RandomUserPartitionScheme.get_group_for_user(self.MOCK_COURSE_ID, self.user, self.user_partition)
|
||||
self.assertEqual(group1_id, group2_id)
|
||||
|
||||
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)
|
||||
|
||||
def test_empty_partition(self):
|
||||
empty_partition = UserPartition(
|
||||
self.TEST_ID,
|
||||
|
||||
Reference in New Issue
Block a user