'When an email address is added to multiple cohorts, the last cohort assignment should be respected.
Then, when a user signs up for the course with that email address,
the user should automatically be added to that cohort and not a random cohort.'

def test_get_cohort_multiple_preassignments(self):

    course = modulestore().get_course(self.toy_course_key)
    cohort = CohortFactory(course_id=course.id, name='TestCohort', users=[])
    cohort2 = CohortFactory(course_id=course.id, name='RandomCohort', users=[])
    config_course_cohorts(course, is_cohorted=True)
    (user, previous_cohort, prereg) = cohorts.add_user_to_cohort(cohort, 'email@example.com')
    self.assertEquals((user, previous_cohort, prereg), (None, None, True))
    (user, previous_cohort, prereg) = cohorts.add_user_to_cohort(cohort2, 'email@example.com')
    self.assertEquals((user, previous_cohort, prereg), (None, None, True))
    user = UserFactory(username='test', email='email@example.com')
    self.assertEquals(cohorts.get_cohort(user, course.id).id, cohort2.id, 'User    should    be    assigned    to    the    right    cohort')
