'Test the CSV output for the anonymized user ids.'

@patch.object(lms.djangoapps.instructor.views.api, 'anonymous_id_for_user', Mock(return_value='42'))
@patch.object(lms.djangoapps.instructor.views.api, 'unique_id_for_user', Mock(return_value='41'))
def test_get_anon_ids(self):

    url = reverse('get_anon_ids', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {})
    self.assertEqual(response['Content-Type'], 'text/csv')
    body = response.content.replace('\r', '')
    self.assertTrue(body.startswith('"User    ID","Anonymized    User    ID","Course    Specific    Anonymized    User    ID"\n"{user_id}","41","42"\n'.format(user_id=self.students[0].id)))
    self.assertTrue(body.endswith('"{user_id}","41","42"\n'.format(user_id=self.students[(-1)].id)))
