Merge pull request #19973 from edx/douglashall/PROD-60
PROD-60 Check GeneratedCertificate.download_url before using HTML cert URL.
This commit is contained in:
@@ -65,7 +65,7 @@ def format_certificate_for_user(username, cert):
|
||||
"is_passing": is_passing_status(cert.status),
|
||||
"is_pdf_certificate": bool(cert.download_url),
|
||||
"download_url": (
|
||||
get_certificate_url(cert.user.id, cert.course_id, user_certificate=cert)
|
||||
cert.download_url or get_certificate_url(cert.user.id, cert.course_id, user_certificate=cert)
|
||||
if cert.status == CertificateStatuses.downloadable
|
||||
else None
|
||||
),
|
||||
|
||||
@@ -15,6 +15,7 @@ from course_modes.models import CourseMode
|
||||
from lms.djangoapps.certificates.apis.v0.views import CertificatesDetailView, CertificatesListView
|
||||
from lms.djangoapps.certificates.models import CertificateStatuses
|
||||
from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory
|
||||
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
|
||||
from openedx.core.djangoapps.oauth_dispatch.toggles import ENFORCE_JWT_SCOPES
|
||||
from openedx.core.djangoapps.user_api.tests.factories import UserPreferenceFactory
|
||||
from openedx.core.djangoapps.user_authn.tests.utils import AuthType, AuthAndScopesTestMixin, JWT_AUTH_TYPES
|
||||
@@ -116,6 +117,13 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC
|
||||
display_name='Verified Course',
|
||||
self_paced=True,
|
||||
)
|
||||
cls.course_overview = CourseOverviewFactory.create(
|
||||
id=cls.course.id,
|
||||
display_org_with_default='edx',
|
||||
display_name='Verified Course',
|
||||
cert_html_view_enabled=True,
|
||||
self_paced=True,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
freezer = freeze_time(self.now)
|
||||
@@ -268,7 +276,7 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC
|
||||
self.assertEqual(len(resp.data), 0)
|
||||
|
||||
# Test student with 1 certificate
|
||||
with self.assertNumQueries(30):
|
||||
with self.assertNumQueries(17):
|
||||
resp = self.get_response(
|
||||
AuthType.jwt,
|
||||
requesting_user=self.student,
|
||||
@@ -285,6 +293,13 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC
|
||||
display_name='Test Course',
|
||||
self_paced=True,
|
||||
)
|
||||
CourseOverviewFactory.create(
|
||||
id=course.id,
|
||||
display_org_with_default='edx',
|
||||
display_name='Test Course',
|
||||
cert_html_view_enabled=True,
|
||||
self_paced=True,
|
||||
)
|
||||
GeneratedCertificateFactory.create(
|
||||
user=student_2_certs,
|
||||
course_id=self.course.id,
|
||||
@@ -301,7 +316,7 @@ class CertificatesListRestApiTest(AuthAndScopesTestMixin, SharedModuleStoreTestC
|
||||
download_url='www.google.com',
|
||||
grade="0.88",
|
||||
)
|
||||
with self.assertNumQueries(30):
|
||||
with self.assertNumQueries(17):
|
||||
resp = self.get_response(
|
||||
AuthType.jwt,
|
||||
requesting_user=student_2_certs,
|
||||
|
||||
Reference in New Issue
Block a user