'If the email address already exists, but the username is different,
assume it is the correct user and just register the user in the course.'

def test_user_with_already_existing_email_in_csv(self):

    csv_content = 'test_student@example.com,test_student_1,tester1,USA\ntest_student@example.com,test_student_2,tester2,US'
    uploaded_file = SimpleUploadedFile('temp.csv', csv_content)
    response = self.client.post(self.url, {'students_list': uploaded_file})
    self.assertEqual(response.status_code, 200)
    data = json.loads(response.content)
    warning_message = 'An    account    with    email    {email}    exists    but    the    provided    username    {username}    is    different.    Enrolling    anyway    with    {email}.'.format(email='test_student@example.com', username='test_student_2')
    self.assertNotEquals(len(data['warnings']), 0)
    self.assertEquals(data['warnings'][0]['response'], warning_message)
    user = User.objects.get(email='test_student@example.com')
    self.assertTrue(CourseEnrollment.is_enrolled(user, self.course.id))
    manual_enrollments = ManualEnrollmentAudit.objects.all()
    self.assertEqual(manual_enrollments.count(), 1)
    self.assertTrue(manual_enrollments[0].state_transition, UNENROLLED_TO_ENROLLED)
