Commit da675e52 by Ahsan Ulhaq

Learner certificates should not be findable before the available date

LEARNER-3298
parent dcb77ff7
...@@ -43,7 +43,8 @@ class CertificateWebViewTest(EventsTestMixin, UniqueCourseTest): ...@@ -43,7 +43,8 @@ class CertificateWebViewTest(EventsTestMixin, UniqueCourseTest):
settings=course_settings settings=course_settings
) )
self.course_fixture.add_advanced_settings({ self.course_fixture.add_advanced_settings({
"cert_html_view_enabled": {"value": "true"} "cert_html_view_enabled": {"value": "true"},
"certificates_display_behavior": {"value": "early_with_info"},
}) })
self.course_fixture.install() self.course_fixture.install()
self.user_id = "99" # we have created a user with this id in fixture self.user_id = "99" # we have created a user with this id in fixture
......
...@@ -657,6 +657,35 @@ class CertificatesViewsTests(CommonCertificatesTestCase): ...@@ -657,6 +657,35 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
self.assertIn("We cannot find a certificate with this URL or ID number.", response.content) self.assertIn("We cannot find a certificate with this URL or ID number.", response.content)
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
def test_html_view_for_non_viewable_certificate(self):
"""
Tests that Certificate HTML Web View returns "Cannot Find Certificate" if certificate is not viewable yet.
"""
test_certificates = [
{
'id': 0,
'name': 'Certificate Name 0',
'signatories': [],
'version': 1,
'is_active': True
}
]
self.course.certificates = {'certificates': test_certificates}
self.course.cert_html_view_enabled = True
self.course.certificate_available_date = datetime.datetime.today() + datetime.timedelta(days=1)
self.course.save()
self.store.update_item(self.course, self.user.id)
test_url = get_certificate_url(
user_id=self.user.id,
course_id=unicode(self.course.id)
)
response = self.client.get(test_url)
self.assertIn("Invalid Certificate", response.content)
self.assertIn("Cannot Find Certificate", response.content)
self.assertIn("We cannot find a certificate with this URL or ID number.", response.content)
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
def test_render_html_view_with_valid_signatories(self): def test_render_html_view_with_valid_signatories(self):
self._add_course_certificates(count=1, signatory_count=2) self._add_course_certificates(count=1, signatory_count=2)
test_url = get_certificate_url( test_url = get_certificate_url(
...@@ -871,8 +900,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase): ...@@ -871,8 +900,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
@ddt.data( @ddt.data(
(-2, True), (-2, True),
(-2, False), (-2, False)
(10, False)
) )
@ddt.unpack @ddt.unpack
def test_html_view_certificate_available_date_for_instructor_paced_courses(self, cert_avail_delta, self_paced): def test_html_view_certificate_available_date_for_instructor_paced_courses(self, cert_avail_delta, self_paced):
......
...@@ -43,7 +43,7 @@ from openedx.core.djangoapps.catalog.utils import get_course_run_details ...@@ -43,7 +43,7 @@ from openedx.core.djangoapps.catalog.utils import get_course_run_details
from openedx.core.djangoapps.lang_pref.api import released_languages from openedx.core.djangoapps.lang_pref.api import released_languages
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.lib.courses import course_image_url from openedx.core.lib.courses import course_image_url
from openedx.core.djangoapps.certificates.api import display_date_for_certificate from openedx.core.djangoapps.certificates.api import display_date_for_certificate, certificates_viewable_for_course
from student.models import LinkedInAddToProfileConfiguration from student.models import LinkedInAddToProfileConfiguration
from util import organizations_helpers as organization_api from util import organizations_helpers as organization_api
from util.date_utils import strftime_localized from util.date_utils import strftime_localized
...@@ -516,6 +516,13 @@ def render_html_view(request, user_id, course_id): ...@@ -516,6 +516,13 @@ def render_html_view(request, user_id, course_id):
log.info(error_str, course_id, user_id, str(exception)) log.info(error_str, course_id, user_id, str(exception))
return _render_invalid_certificate(course_id, platform_name, configuration) return _render_invalid_certificate(course_id, platform_name, configuration)
if not certificates_viewable_for_course(course):
log.info(
"Invalid cert: Certificate for %s is not viewable yet.",
course_id,
)
return _render_invalid_certificate(course_id, platform_name, configuration)
# Kick the user back to the "Invalid" screen if the feature is disabled for the course # Kick the user back to the "Invalid" screen if the feature is disabled for the course
if not course.cert_html_view_enabled: if not course.cert_html_view_enabled:
log.info( log.info(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment