'Ensures cohort_name is a valid cohort for course_id.
Returns the cohort if valid, raises an error otherwise.'

@classmethod
def ensure_valid_cohort(cls, cohort_name, course_id):

    if (cohort_name is None):
        raise ValueError('Cannot    create    a    CohortTarget    without    specifying    a    cohort_name.')
    try:
        cohort = get_cohort_by_name(name=cohort_name, course_key=course_id)
    except CourseUserGroup.DoesNotExist:
        raise ValueError('Cohort    {cohort}    does    not    exist    in    course    {course_id}'.format(cohort=cohort_name, course_id=course_id))
    return cohort
