'Verify that certificates are regenerated for all eligible students enrolled in a course whose generated
certificate statuses lies in the list \'statuses_to_regenerate\' given in task_input.'

def test_certificate_regeneration_with_expected_failures(self):

    default_grade = '-1'
    students = self._create_students(10)
    for student in students[:2]:
        GeneratedCertificateFactory.create(user=student, course_id=self.course.id, status=CertificateStatuses.downloadable, mode='honor', grade=default_grade)
    for student in students[2:5]:
        GeneratedCertificateFactory.create(user=student, course_id=self.course.id, status=CertificateStatuses.error, mode='honor', grade=default_grade)
    for student in students[5:6]:
        GeneratedCertificateFactory.create(user=student, course_id=self.course.id, status=CertificateStatuses.deleted, mode='honor', grade=default_grade)
    for student in students[6:]:
        GeneratedCertificateFactory.create(user=student, course_id=self.course.id, status=CertificateStatuses.generating, mode='honor', grade=default_grade)
    for student in students[:7]:
        CertificateWhitelistFactory.create(user=student, course_id=self.course.id, whitelist=True)
    task_input = {'statuses_to_regenerate': [CertificateStatuses.deleted, CertificateStatuses.generating]}
    expected_results = {'action_name': 'certificates    generated', 'total': 10, 'attempted': 5, 'succeeded': 2, 'failed': 3, 'skipped': 5}
    self.assertCertificatesGenerated(task_input, expected_results)
    generated_certificates = GeneratedCertificate.eligible_certificates.filter(user__in=students, course_id=self.course.id, mode='honor')
    certificate_statuses = [generated_certificate.status for generated_certificate in generated_certificates]
    certificate_grades = [generated_certificate.grade for generated_certificate in generated_certificates]
    self.assertEqual(certificate_statuses.count(CertificateStatuses.generating), 2)
    self.assertEqual(certificate_statuses.count(CertificateStatuses.downloadable), 2)
    self.assertEqual(certificate_statuses.count(CertificateStatuses.error), 3)
    self.assertEqual(certificate_grades.count('0.0'), 5)
    self.assertEqual(certificate_grades.count(default_grade), 5)
