diff --git a/common/test/acceptance/fixtures/certificates.py b/common/test/acceptance/fixtures/certificates.py index f12573cad9..346037801d 100644 --- a/common/test/acceptance/fixtures/certificates.py +++ b/common/test/acceptance/fixtures/certificates.py @@ -15,6 +15,13 @@ class CertificateConfigFixtureError(Exception): pass +class CertificateConfigUpdateFixtureError(Exception): + """ + Error occurred while updating certificate config fixture. + """ + pass + + class CertificateConfigFixture(StudioApiFixture): """ Fixture to create certificates configuration for a course @@ -44,3 +51,22 @@ class CertificateConfigFixture(StudioApiFixture): ) return self + + def update_certificate(self, certificate_id): + """ + Update the certificates config data to certificate endpoint. + """ + response = self.session.put( + '{}/certificates/{}/{}'.format(STUDIO_BASE_URL, self.course_id, certificate_id), + data=json.dumps(self.certificates), + headers=self.headers + ) + + if not response.ok: + raise CertificateConfigUpdateFixtureError( + "Could not update certificate {0}. Status was {1}".format( + json.dumps(self.certificates), response.status_code + ) + ) + + return self diff --git a/common/test/acceptance/pages/lms/instructor_dashboard.py b/common/test/acceptance/pages/lms/instructor_dashboard.py index 83e4292896..977d391b87 100644 --- a/common/test/acceptance/pages/lms/instructor_dashboard.py +++ b/common/test/acceptance/pages/lms/instructor_dashboard.py @@ -1056,6 +1056,13 @@ class CertificatesPage(PageObject): """ return self.get_selector('#btn-start-generating-certificates') + @property + def generate_certificates_disabled_button(self): # pylint: disable=invalid-name + """ + Returns the disabled state of button + """ + return self.get_selector('#disabled-btn-start-generating-certificates') + @property def certificate_generation_status(self): """ diff --git a/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py b/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py index 93f2043b2d..0b2201c5e6 100644 --- a/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py +++ b/common/test/acceptance/tests/lms/test_lms_instructor_dashboard.py @@ -22,6 +22,7 @@ from ...pages.lms.problem import ProblemPage from ...pages.lms.track_selection import TrackSelectionPage from ...pages.lms.pay_and_verify import PaymentAndVerificationFlow, FakePaymentPage from common.test.acceptance.tests.helpers import disable_animations +from ...fixtures.certificates import CertificateConfigFixture class BaseInstructorDashboardTest(EventsTestMixin, UniqueCourseTest): @@ -589,12 +590,37 @@ class CertificatesTest(BaseInstructorDashboardTest): def setUp(self): super(CertificatesTest, self).setUp() - self.course_fixture = CourseFixture(**self.course_info).install() + self.test_certificate_config = { + 'id': 1, + 'name': 'Certificate name', + 'description': 'Certificate description', + 'course_title': 'Course title override', + 'signatories': [], + 'version': 1, + 'is_active': True + } + CourseFixture(**self.course_info).install() + self.cert_fixture = CertificateConfigFixture(self.course_id, self.test_certificate_config) + self.cert_fixture.install() self.user_name, self.user_id = self.log_in_as_instructor() self.instructor_dashboard_page = self.visit_instructor_dashboard() self.certificates_section = self.instructor_dashboard_page.select_certificates() disable_animations(self.certificates_section) + def test_generate_certificates_buttons_is_disable(self): + """ + Scenario: On the Certificates tab of the Instructor Dashboard, Generate Certificates button is disable. + Given that I am on the Certificates tab on the Instructor Dashboard + The instructor-generation and cert_html_view_enabled feature flags have been enabled + But the certificate is not active in settings. + Then I see a 'Generate Certificates' button disabled + """ + self.test_certificate_config['is_active'] = False + self.cert_fixture.update_certificate(1) + self.browser.refresh() + self.assertFalse(self.certificates_section.generate_certificates_button.visible) + self.assertTrue(self.certificates_section.generate_certificates_disabled_button.visible) + def test_generate_certificates_buttons_is_visible(self): """ Scenario: On the Certificates tab of the Instructor Dashboard, Generate Certificates button is visible. diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 8034d3d0cf..c967476f2a 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -299,6 +299,7 @@ def _section_certificates(course): 'enabled_for_course': certs_api.cert_generation_enabled(course.id), 'instructor_generation_enabled': instructor_generation_enabled, 'html_cert_enabled': html_cert_enabled, + 'active_certificate': certs_api.get_active_web_certificate(course), 'certificate_statuses': GeneratedCertificate.get_unique_statuses(course_key=course.id), 'urls': { 'generate_example_certificates': reverse( diff --git a/lms/templates/instructor/instructor_dashboard_2/certificates.html b/lms/templates/instructor/instructor_dashboard_2/certificates.html index 43f039308d..bc3060f060 100644 --- a/lms/templates/instructor/instructor_dashboard_2/certificates.html +++ b/lms/templates/instructor/instructor_dashboard_2/certificates.html @@ -73,7 +73,12 @@ import json