From 08d1268c2865c2e8b532f75d92f7f097cda25989 Mon Sep 17 00:00:00 2001 From: Bill DeRusha Date: Mon, 14 Dec 2015 11:32:24 -0500 Subject: [PATCH] Disable cert generation for audit only courses --- .../contentstore/views/certificates.py | 6 +++- .../views/tests/test_certificates.py | 35 +++++++++++++++++++ cms/templates/certificates.html | 10 +++++- .../test_studio_settings_certificates.py | 8 +++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/views/certificates.py b/cms/djangoapps/contentstore/views/certificates.py index 614a690bb2..27a0382448 100644 --- a/cms/djangoapps/contentstore/views/certificates.py +++ b/cms/djangoapps/contentstore/views/certificates.py @@ -359,7 +359,10 @@ def certificates_list_handler(request, course_key_string): course_id=course.id, include_expired=True ) if mode.slug != 'audit' ] - if len(course_modes) > 0: + + has_certificate_modes = len(course_modes) > 0 + + if has_certificate_modes: certificate_web_view_url = get_lms_link_for_certificate_web_view( user_id=request.user.id, course_key=course_key, @@ -382,6 +385,7 @@ def certificates_list_handler(request, course_key_string): 'course_outline_url': course_outline_url, 'upload_asset_url': upload_asset_url, 'certificates': certificates, + 'has_certificate_modes': has_certificate_modes, 'course_modes': course_modes, 'certificate_web_view_url': certificate_web_view_url, 'is_active': is_active, diff --git a/cms/djangoapps/contentstore/views/tests/test_certificates.py b/cms/djangoapps/contentstore/views/tests/test_certificates.py index a62097bdf5..4c60792d2a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/views/tests/test_certificates.py @@ -195,6 +195,7 @@ class CertificatesBaseTestCase(object): self.assertTrue('must have name of the certificate' in context.exception) +@ddt.ddt @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) class CertificatesListHandlerTestCase(EventTestMixin, CourseTestCase, CertificatesBaseTestCase, HelperMethods): """ @@ -340,6 +341,40 @@ class CertificatesListHandlerTestCase(EventTestMixin, CourseTestCase, Certificat self.assertContains(response, 'verified') self.assertNotContains(response, 'audit') + def test_audit_only_disables_cert(self): + """ + Tests audit course mode is skipped when rendering certificates page. + """ + CourseModeFactory.create(course_id=self.course.id, mode_slug='audit') + response = self.client.get_html( + self._url(), + ) + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'This course does not use a mode that offers certificates.') + self.assertNotContains(response, 'This module is not enabled.') + self.assertNotContains(response, 'Loading') + + @ddt.data( + ['audit', 'verified'], + ['verified'], + ['audit', 'verified', 'credit'], + ['verified', 'credit'], + ['professional'] + ) + def test_non_audit_enables_cert(self, slugs): + """ + Tests audit course mode is skipped when rendering certificates page. + """ + for slug in slugs: + CourseModeFactory.create(course_id=self.course.id, mode_slug=slug) + response = self.client.get_html( + self._url(), + ) + self.assertEqual(response.status_code, 200) + self.assertNotContains(response, 'This course does not use a mode that offers certificates.') + self.assertNotContains(response, 'This module is not enabled.') + self.assertContains(response, 'Loading') + def test_assign_unique_identifier_to_certificates(self): """ Test certificates have unique ids diff --git a/cms/templates/certificates.html b/cms/templates/certificates.html index 2b144c80d1..d038cfe37e 100644 --- a/cms/templates/certificates.html +++ b/cms/templates/certificates.html @@ -30,7 +30,9 @@ CMS.User.isGlobalStaff = '${is_global_staff}'=='True' ? true : false; <%block name="requirejs"> require(["js/certificates/factories/certificates_page_factory"], function(CertificatesPageFactory) { - CertificatesPageFactory(${escape_json_dumps(certificates) | n}, "${certificate_url}", "${course_outline_url}", ${escape_json_dumps(course_modes) | n}, ${escape_json_dumps(certificate_web_view_url) | n}, ${escape_json_dumps(is_active) | n}, ${escape_json_dumps(certificate_activation_handler_url) | n} ); + if(${escape_json_dumps(has_certificate_modes)}) { + CertificatesPageFactory(${escape_json_dumps(certificates) | n}, "${certificate_url}", "${course_outline_url}", ${escape_json_dumps(course_modes) | n}, ${escape_json_dumps(certificate_web_view_url) | n}, ${escape_json_dumps(is_active) | n}, ${escape_json_dumps(certificate_activation_handler_url) | n} ); + } }); @@ -56,6 +58,12 @@ CMS.User.isGlobalStaff = '${is_global_staff}'=='True' ? true : false; ${_("This module is not enabled.")}

+ % elif not has_certificate_modes: +
+

+ ${_("This course does not use a mode that offers certificates.")} +

+
% else:

${_("Loading")}

diff --git a/common/test/acceptance/tests/studio/test_studio_settings_certificates.py b/common/test/acceptance/tests/studio/test_studio_settings_certificates.py index f6be0db982..2a309df633 100644 --- a/common/test/acceptance/tests/studio/test_studio_settings_certificates.py +++ b/common/test/acceptance/tests/studio/test_studio_settings_certificates.py @@ -3,7 +3,9 @@ Acceptance tests for Studio's Setting pages """ import re import uuid + from .base_studio_test import StudioCourseTest +from ...pages.lms.create_mode import ModeCreationPage from ...pages.studio.settings_certificates import CertificatesPage from ...pages.studio.settings_advanced import AdvancedSettingsPage @@ -28,6 +30,12 @@ class CertificatesTest(StudioCourseTest): ) self.course_advanced_settings = dict() + # Add a verified mode to the course + ModeCreationPage( + self.browser, self.course_id, mode_slug=u'verified', mode_display_name=u'Verified Certificate', + min_price=10, suggested_prices='10,20' + ).visit() + def make_signatory_data(self, prefix='First'): """ Makes signatory dict which can be used in the tests to create certificates