Commit c4823c5e by rabia23 Committed by rabiaiftikhar

EDUCATOR-394 Disable self generation certificates when course is reset to instructor-paced.

parent 31912ac1
...@@ -12,6 +12,7 @@ from common.test.acceptance.pages.lms.course_info import CourseInfoPage ...@@ -12,6 +12,7 @@ from common.test.acceptance.pages.lms.course_info import CourseInfoPage
from common.test.acceptance.pages.lms.courseware import CoursewarePage from common.test.acceptance.pages.lms.courseware import CoursewarePage
from common.test.acceptance.pages.lms.progress import ProgressPage from common.test.acceptance.pages.lms.progress import ProgressPage
from common.test.acceptance.pages.lms.tab_nav import TabNavPage from common.test.acceptance.pages.lms.tab_nav import TabNavPage
from common.test.acceptance.pages.lms.instructor_dashboard import InstructorDashboardPage
@attr(shard=5) @attr(shard=5)
...@@ -158,6 +159,7 @@ class CertificateProgressPageTest(UniqueCourseTest): ...@@ -158,6 +159,7 @@ class CertificateProgressPageTest(UniqueCourseTest):
self.courseware_page = CoursewarePage(self.browser, self.course_id) self.courseware_page = CoursewarePage(self.browser, self.course_id)
self.course_home_page = CourseHomePage(self.browser, self.course_id) self.course_home_page = CourseHomePage(self.browser, self.course_id)
self.tab_nav = TabNavPage(self.browser) self.tab_nav = TabNavPage(self.browser)
self.instructor_dashboard_page = InstructorDashboardPage(self.browser, self.course_id)
def log_in_as_unique_user(self): def log_in_as_unique_user(self):
""" """
...@@ -168,7 +170,8 @@ class CertificateProgressPageTest(UniqueCourseTest): ...@@ -168,7 +170,8 @@ class CertificateProgressPageTest(UniqueCourseTest):
username="testprogress", username="testprogress",
email="progress@example.com", email="progress@example.com",
password="testuser", password="testuser",
course_id=self.course_id course_id=self.course_id,
staff=True,
).visit() ).visit()
def test_progress_page_has_view_certificate_button(self): def test_progress_page_has_view_certificate_button(self):
...@@ -245,4 +248,4 @@ class CertificateProgressPageTest(UniqueCourseTest): ...@@ -245,4 +248,4 @@ class CertificateProgressPageTest(UniqueCourseTest):
# Submit the answer # Submit the answer
self.courseware_page.q(css='button.submit').click() self.courseware_page.q(css='button.submit').click()
self.courseware_page.wait_for_ajax() self.courseware_page.wait_for_ajax()
\ No newline at end of file
...@@ -54,6 +54,7 @@ from django.conf import settings ...@@ -54,6 +54,7 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models, transaction from django.db import models, transaction
from django.db.utils import IntegrityError
from django.db.models import Count from django.db.models import Count
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -890,10 +891,13 @@ class CertificateGenerationCourseSetting(TimeStampedModel): ...@@ -890,10 +891,13 @@ class CertificateGenerationCourseSetting(TimeStampedModel):
is_enabled (boolean): Whether to enable or disable self-generated certificates. is_enabled (boolean): Whether to enable or disable self-generated certificates.
""" """
CertificateGenerationCourseSetting.objects.create( certificate_generation_course_setting = CertificateGenerationCourseSetting(course_key=course_key,
course_key=course_key, enabled=is_enabled)
enabled=is_enabled try:
) with transaction.atomic():
certificate_generation_course_setting.save()
except IntegrityError:
pass
class CertificateGenerationConfiguration(ConfigurationModel): class CertificateGenerationConfiguration(ConfigurationModel):
......
""" Signal handler for enabling self-generated certificates by default """ Signal handler for enabling self-generated certificates for self-paced
for self-paced courses. courses and disabling for instructor-paced courses.
""" """
from celery.task import task from celery.task import task
from django.dispatch.dispatcher import receiver from django.dispatch.dispatcher import receiver
from certificates.models import CertificateGenerationCourseSetting from certificates.models import CertificateGenerationCourseSetting
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from xmodule.modulestore.django import SignalHandler, modulestore
from xmodule.modulestore.django import SignalHandler
@receiver(SignalHandler.course_published) @receiver(SignalHandler.course_published)
def _listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument def _listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument
""" Catches the signal that a course has been published in Studio and """ Catches the signal that a course has been published in Studio and
enable the self-generated certificates by default for self-paced enable/disable the self-generated certificates for courses according to pacing.
courses.
""" """
enable_self_generated_certs.delay(unicode(course_key)) set_self_generated_certs.delay(unicode(course_key))
@task() @task()
def enable_self_generated_certs(course_key): def set_self_generated_certs(course_key):
"""Enable the self-generated certificates by default for self-paced courses.""" """Enable or disable self-generated certificates for a course according to pacing."""
course_key = CourseKey.from_string(course_key) course_key = CourseKey.from_string(course_key)
course = CourseOverview.get_from_id(course_key) course = modulestore().get_course(course_key)
is_enabled_for_course = CertificateGenerationCourseSetting.is_enabled_for_course(course_key) CertificateGenerationCourseSetting.set_enabled_for_course(course_key, course.self_paced)
if course.self_paced and not is_enabled_for_course:
CertificateGenerationCourseSetting.set_enabled_for_course(course_key, True)
""" Unit tests for enabling self-generated certificates by default """ Unit tests for enabling self-generated certificates for
for self-paced courses. self-paced courses and disabling for instructor-paced courses.
""" """
from certificates import api as certs_api from certificates import api as certs_api
from certificates.models import CertificateGenerationConfiguration from certificates.models import CertificateGenerationConfiguration
...@@ -10,8 +10,8 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase ...@@ -10,8 +10,8 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
class SelfGeneratedCertsSignalTest(ModuleStoreTestCase): class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
""" Tests for enabling self-generated certificates by default """ Tests for enabling/disabling self-generated certificates
for self-paced courses. according to pacing.
""" """
def setUp(self): def setUp(self):
...@@ -22,10 +22,20 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase): ...@@ -22,10 +22,20 @@ class SelfGeneratedCertsSignalTest(ModuleStoreTestCase):
CertificateGenerationConfiguration.objects.create(enabled=True) CertificateGenerationConfiguration.objects.create(enabled=True)
def test_cert_generation_enabled_for_self_paced(self): def test_cert_generation_enabled_for_self_paced(self):
""" Verify the signal enable the self-generated certificates by default for """ Verify the signal enable the self-generated certificates for
self-paced courses. self-paced courses.
""" """
self.assertFalse(certs_api.cert_generation_enabled(self.course.id)) self.assertFalse(certs_api.cert_generation_enabled(self.course.id))
_listen_for_course_publish('store', self.course.id) _listen_for_course_publish('store', self.course.id)
self.assertTrue(certs_api.cert_generation_enabled(self.course.id)) self.assertTrue(certs_api.cert_generation_enabled(self.course.id))
def test_cert_generation_disabled_for_instructor_paced(self):
""" Verify the signal disable the self-generated certificates for
instructor-paced courses.
"""
self.course.self_paced = False
self.store.update_item(self.course, self.user.id)
_listen_for_course_publish('store', self.course.id)
self.assertFalse(certs_api.cert_generation_enabled(self.course.id))
...@@ -1331,9 +1331,6 @@ class ProgressPageTests(ModuleStoreTestCase): ...@@ -1331,9 +1331,6 @@ class ProgressPageTests(ModuleStoreTestCase):
# Enable the feature, but do not enable it for this course # Enable the feature, but do not enable it for this course
CertificateGenerationConfiguration(enabled=True).save() CertificateGenerationConfiguration(enabled=True).save()
# Enable certificate generation for this course
certs_api.set_cert_generation_enabled(self.course.id, True)
# Course certificate configurations # Course certificate configurations
certificates = [ certificates = [
{ {
...@@ -1352,6 +1349,13 @@ class ProgressPageTests(ModuleStoreTestCase): ...@@ -1352,6 +1349,13 @@ class ProgressPageTests(ModuleStoreTestCase):
self.course.save() self.course.save()
self.store.update_item(self.course, self.user.id) self.store.update_item(self.course, self.user.id)
# verify that certificate web view button disappears for disabled self-generation certificates
resp = self._get_progress_page()
self.assertNotContains(resp, u"View Certificate")
# Enable certificate self-generation for this course
certs_api.set_cert_generation_enabled(self.course.id, True)
resp = self._get_progress_page() resp = self._get_progress_page()
self.assertContains(resp, u"View Certificate") self.assertContains(resp, u"View Certificate")
...@@ -1363,6 +1367,11 @@ class ProgressPageTests(ModuleStoreTestCase): ...@@ -1363,6 +1367,11 @@ class ProgressPageTests(ModuleStoreTestCase):
certificates[0]['is_active'] = False certificates[0]['is_active'] = False
self.store.update_item(self.course, self.user.id) self.store.update_item(self.course, self.user.id)
# Re-enable certificate self-generation for this course because whenever
# course content changes then self-generation changes according to pacing
# (EDUCATOR-394)
certs_api.set_cert_generation_enabled(self.course.id, True)
resp = self._get_progress_page() resp = self._get_progress_page()
self.assertNotContains(resp, u"View Your Certificate") self.assertNotContains(resp, u"View Your Certificate")
self.assertNotContains(resp, u"You can now view your certificate") self.assertNotContains(resp, u"You can now view your certificate")
...@@ -1493,6 +1502,9 @@ class ProgressPageTests(ModuleStoreTestCase): ...@@ -1493,6 +1502,9 @@ class ProgressPageTests(ModuleStoreTestCase):
self.course.save() self.course.save()
self.store.update_item(self.course, self.user.id) self.store.update_item(self.course, self.user.id)
# Enable certificate generation for this course (EDUCATOR-394)
certs_api.set_cert_generation_enabled(self.course.id, True)
resp = self._get_progress_page() resp = self._get_progress_page()
self.assertContains(resp, u"View Certificate") self.assertContains(resp, u"View Certificate")
self.assert_invalidate_certificate(generated_certificate) self.assert_invalidate_certificate(generated_certificate)
......
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