'Make sure cohorts.add_cohort() properly adds a cohort to a course and handles
errors.'

@patch('openedx.core.djangoapps.course_groups.cohorts.tracker')
def test_add_cohort(self, mock_tracker):

    assignment_type = CourseCohort.RANDOM
    course = modulestore().get_course(self.toy_course_key)
    added_cohort = cohorts.add_cohort(course.id, 'My    Cohort', assignment_type)
    mock_tracker.emit.assert_any_call('edx.cohort.creation_requested', {'cohort_name': added_cohort.name, 'cohort_id': added_cohort.id})
    self.assertEqual(added_cohort.name, 'My    Cohort')
    self.assertRaises(ValueError, (lambda : cohorts.add_cohort(course.id, 'My    Cohort', assignment_type)))
    does_not_exist_course_key = CourseLocator('course', 'does_not', 'exist')
    self.assertRaises(ValueError, (lambda : cohorts.add_cohort(does_not_exist_course_key, 'My    Cohort', assignment_type)))
