'Test that changes made *after* migration, but *before* turning on new code are handled properly'

def test_post_cohortmembership_fix(self):

    config_course_cohorts(self.course1, is_cohorted=True, auto_cohorts=['Course1AutoGroup1', 'Course1AutoGroup2'])
    cohort_handler(self.request, unicode(self.course1.id))
    course_1_auto_cohort_1 = get_cohort_by_name(self.course1.id, 'Course1AutoGroup1')
    course_1_auto_cohort_2 = get_cohort_by_name(self.course1.id, 'Course1AutoGroup2')
    membership1 = CohortMembership(course_id=course_1_auto_cohort_1.course_id, user=self.user1, course_user_group=course_1_auto_cohort_1)
    membership1.save()
    membership2 = CohortMembership(course_id=course_1_auto_cohort_1.course_id, user=self.user2, course_user_group=course_1_auto_cohort_1)
    membership2.save()
    course_1_auto_cohort_2.users.add(self.user1)
    course_1_auto_cohort_2.users.add(self.user2)
    course_1_auto_cohort_1.users.remove(self.user2)
    call_command('post_cohort_membership_fix')
    self.assertEqual(self.user1.course_groups.count(), 2)
    self.assertEqual(CohortMembership.objects.get(user=self.user2).course_user_group.name, 'Course1AutoGroup1')
    user2_cohorts = list(self.user2.course_groups.values_list('name', flat=True))
    self.assertEqual(user2_cohorts, ['Course1AutoGroup2'])
    call_command('post_cohort_membership_fix', commit='commit')
    self.assertEqual(self.user1.course_groups.count(), 1)
    self.assertEqual(CohortMembership.objects.filter(user=self.user1).count(), 1)
    self.assertEqual(self.user2.course_groups.count(), 1)
    self.assertEqual(CohortMembership.objects.filter(user=self.user2).count(), 1)
    self.assertEqual(CohortMembership.objects.get(user=self.user2).course_user_group.name, 'Course1AutoGroup2')
    user2_cohorts = list(self.user2.course_groups.values_list('name', flat=True))
    self.assertEqual(user2_cohorts, ['Course1AutoGroup2'])
