'Test that existing audit certificates remain eligible even if cert
generation is re-run.'

@ddt.data((CertificateStatuses.downloadable, (datetime.now(pytz.UTC) - timedelta(days=2)), 'Pass', CertificateStatuses.generating), (CertificateStatuses.downloadable, (datetime.now(pytz.UTC) - timedelta(hours=1)), 'Pass', CertificateStatuses.audit_passing), (CertificateStatuses.audit_passing, (datetime.now(pytz.UTC) - timedelta(hours=1)), 'Pass', CertificateStatuses.audit_passing), (CertificateStatuses.audit_notpassing, (datetime.now(pytz.UTC) - timedelta(hours=1)), 'Pass', CertificateStatuses.audit_passing), (CertificateStatuses.audit_notpassing, (datetime.now(pytz.UTC) - timedelta(hours=1)), None, CertificateStatuses.audit_notpassing))
@ddt.unpack
@override_settings(AUDIT_CERT_CUTOFF_DATE=(datetime.now(pytz.UTC) - timedelta(days=1)))
def test_regen_audit_certs_eligibility(self, status, created_date, grade, expected_status):

    CourseEnrollmentFactory(user=self.user_2, course_id=self.course.id, is_active=True, mode=CourseMode.AUDIT)
    with freezegun.freeze_time(created_date):
        GeneratedCertificateFactory(user=self.user_2, course_id=self.course.id, grade='1.0', status=status, mode=GeneratedCertificate.MODES.audit)
    with mock_passing_grade(grade_pass=grade):
        with patch.object(XQueueInterface, 'send_to_queue') as mock_send:
            mock_send.return_value = (0, None)
            self.xqueue.add_cert(self.user_2, self.course.id)
    self.assertEqual(GeneratedCertificate.objects.get(user=self.user_2, course_id=self.course.id).status, expected_status)
