From 1adc01b45c67f18cfc6562ac918c262dbca1e51d Mon Sep 17 00:00:00 2001 From: adeelehsan Date: Tue, 5 Nov 2019 18:30:55 +0500 Subject: [PATCH] Allow certification regenration for existing honor certificates staff should be able to regenerate certificates for the students who have already earned the certificate using honor mode Prod-612 --- common/djangoapps/course_modes/models.py | 8 +++++-- lms/djangoapps/certificates/queue.py | 3 ++- .../certificates/tests/test_support_views.py | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index 184b8d0a6b..e967fe3f16 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -757,7 +757,7 @@ class CourseMode(models.Model): return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower()) @classmethod - def is_eligible_for_certificate(cls, mode_slug): + def is_eligible_for_certificate(cls, mode_slug, status=None): """ Returns whether or not the given mode_slug is eligible for a certificate. Currently all modes other than 'audit' grant a @@ -769,7 +769,11 @@ class CourseMode(models.Model): ineligible_modes = [cls.AUDIT] if settings.FEATURES['DISABLE_HONOR_CERTIFICATES']: - ineligible_modes.append(cls.HONOR) + # Adding check so that we can regenerate the certificate for learners who have + # already earned the certificate using honor mode + from lms.djangoapps.certificates.models import CertificateStatuses + if mode_slug == cls.HONOR and status != CertificateStatuses.downloadable: + ineligible_modes.append(cls.HONOR) return mode_slug not in ineligible_modes diff --git a/lms/djangoapps/certificates/queue.py b/lms/djangoapps/certificates/queue.py index 46d756d5f1..f692c429f5 100644 --- a/lms/djangoapps/certificates/queue.py +++ b/lms/djangoapps/certificates/queue.py @@ -291,7 +291,8 @@ class XQueueCertInterface(object): mode_is_verified = enrollment_mode in GeneratedCertificate.VERIFIED_CERTS_MODES user_is_verified = IDVerificationService.user_is_verified(student) cert_mode = enrollment_mode - is_eligible_for_certificate = is_whitelisted or CourseMode.is_eligible_for_certificate(enrollment_mode) + is_eligible_for_certificate = is_whitelisted or CourseMode.is_eligible_for_certificate(enrollment_mode, + cert_status) unverified = False # For credit mode generate verified certificate if cert_mode in (CourseMode.CREDIT_MODE, CourseMode.MASTERS): diff --git a/lms/djangoapps/certificates/tests/test_support_views.py b/lms/djangoapps/certificates/tests/test_support_views.py index 63489441c8..d728e9c2df 100644 --- a/lms/djangoapps/certificates/tests/test_support_views.py +++ b/lms/djangoapps/certificates/tests/test_support_views.py @@ -8,11 +8,14 @@ import json import ddt import six +from mock import patch from django.conf import settings from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey +from lms.djangoapps.grades.tests.utils import mock_passing_grade +from lms.djangoapps.certificates import api from lms.djangoapps.certificates.models import CertificateInvalidation, CertificateStatuses, GeneratedCertificate from lms.djangoapps.certificates.tests.factories import CertificateInvalidationFactory from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory @@ -22,6 +25,7 @@ from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory + FEATURES_WITH_CERTS_ENABLED = settings.FEATURES.copy() FEATURES_WITH_CERTS_ENABLED['CERTIFICATES_HTML_VIEW'] = True @@ -299,6 +303,23 @@ class CertificateRegenerateTests(CertificateSupportTestCase): cert = GeneratedCertificate.eligible_certificates.get(user=self.student) self.assertEqual(cert.status, CertificateStatuses.notpassing) + @patch('lms.djangoapps.certificates.queue.XQueueCertInterface._generate_cert') + def test_regenerate_certificate_for_honor_mode(self, mock_generate_cert): + """Test web certificate regenration for the users who have earned the + certificate in honor mode + """ + self.cert.mode = 'honor' + self.cert.download_url = '' + self.cert.save() + + with mock_passing_grade(percent=0.75): + with patch('course_modes.models.CourseMode.mode_for_course') as mock_mode_for_course: + mock_mode_for_course.return_value = 'honor' + api.regenerate_user_certificates(self.student, self.course.id, + course=self.course) + + mock_generate_cert.assert_called() + def test_regenerate_certificate_missing_params(self): # Missing username response = self._regenerate(course_key=self.CERT_COURSE_KEY)