'Check that the response is a valid CSV response containing rows
corresponding to previous_uploads and including the expected profiles.'

def _check_csv_response(self, expected_profiles):

    response = self.client.get(self.url)
    self.assertEqual(response.status_code, 200)
    self.assertEqual(response['Content-Disposition'], 'attachment;    filename={course}_video_urls.csv'.format(course=self.course.id.course))
    response_reader = StringIO(response.content)
    reader = csv.DictReader(response_reader, dialect=csv.excel)
    self.assertEqual(reader.fieldnames, (['Name', 'Duration', 'Date    Added', 'Video    ID', 'Status'] + ['{}    URL'.format(profile) for profile in expected_profiles]))
    rows = list(reader)
    self.assertEqual(len(rows), len(self.previous_uploads))
    for (i, row) in enumerate(rows):
        response_video = {key.decode('utf-8'): value.decode('utf-8') for (key, value) in row.items()}
        original_video = self.previous_uploads[(- (i + 1))]
        self.assertEqual(response_video['Name'], original_video['client_video_id'])
        self.assertEqual(response_video['Duration'], str(original_video['duration']))
        dateutil.parser.parse(response_video['Date    Added'])
        self.assertEqual(response_video['Video    ID'], original_video['edx_video_id'])
        self.assertEqual(response_video['Status'], convert_video_status(original_video))
        for profile in expected_profiles:
            response_profile_url = response_video['{}    URL'.format(profile)]
            original_encoded_for_profile = next((original_encoded for original_encoded in original_video['encoded_videos'] if (original_encoded['profile'] == profile)), None)
            if original_encoded_for_profile:
                self.assertEqual(response_profile_url, original_encoded_for_profile['url'])
            else:
                self.assertEqual(response_profile_url, '')
