'Returns the Group from the specified user partition to which the user
is assigned, via their cohort membership and any mappings from cohorts
to partitions / groups that might exist.
If the user has not yet been assigned to a cohort, an assignment *might*
be created on-the-fly, as determined by the course\'s cohort config.
Any such side-effects will be triggered inside the call to
cohorts.get_cohort().
If the user has no cohort mapping, or there is no (valid) cohort ->
partition group mapping found, the function returns None.'

@classmethod
def get_group_for_user(cls, course_key, user, user_partition, use_cached=True):

    if (get_course_masquerade(user, course_key) and (not is_masquerading_as_specific_student(user, course_key))):
        return get_masquerading_user_group(course_key, user, user_partition)
    cohort = get_cohort(user, course_key, use_cached=use_cached)
    if (cohort is None):
        return None
    (group_id, partition_id) = get_group_info_for_cohort(cohort, use_cached=use_cached)
    if (partition_id is None):
        return None
    if (partition_id != user_partition.id):
        log.warn('partition    mismatch    in    CohortPartitionScheme:    %r', {'requested_partition_id': user_partition.id, 'found_partition_id': partition_id, 'found_group_id': group_id, 'cohort_id': cohort.id})
        return None
    try:
        return user_partition.get_group(group_id)
    except NoSuchUserPartitionGroupError:
        log.warn('group    not    found    in    CohortPartitionScheme:    %r', {'requested_partition_id': user_partition.id, 'requested_group_id': group_id, 'cohort_id': cohort.id}, exc_info=True)
        return None
