Exemple #1
0
 def test_fire_ungenerated_certificate_task_allowed_modes(
         self, enrollment_mode, should_create):
     """
     Test that certificate generation task is fired for only modes that are
     allowed to generate certificates automatically.
     """
     self.user = UserFactory.create()
     self.enrollment = CourseEnrollmentFactory(  # lint-amnesty, pylint: disable=attribute-defined-outside-init
         user=self.user,
         course_id=self.course.id,
         is_active=True,
         mode=enrollment_mode)
     with mock.patch(
             'lms.djangoapps.certificates.signals.generate_certificate.apply_async',
             return_value=None) as mock_generate_certificate_apply_async:
         with override_waffle_switch(AUTO_CERTIFICATE_GENERATION_SWITCH,
                                     active=True):
             fire_ungenerated_certificate_task(self.user, self.course.id)
             task_created = mock_generate_certificate_apply_async.called
             self.assertEqual(task_created, should_create)
Exemple #2
0
 def test_fire_ungenerated_certificate_task_allowed_modes(self, enrollment_mode, should_create):
     """
     Test that certificate generation task is fired for only modes that are
     allowed to generate certificates automatically.
     """
     self.user = UserFactory.create()
     self.enrollment = CourseEnrollmentFactory(
         user=self.user,
         course_id=self.course.id,
         is_active=True,
         mode=enrollment_mode
     )
     with mock.patch(
         'lms.djangoapps.certificates.signals.generate_certificate.apply_async',
         return_value=None
     ) as mock_generate_certificate_apply_async:
         with waffle.waffle().override(waffle.AUTO_CERTIFICATE_GENERATION, active=True):
             fire_ungenerated_certificate_task(self.user, self.course.id)
             task_created = mock_generate_certificate_apply_async.called
             self.assertEqual(task_created, should_create)
    def test_fire_task_allowlist_enabled(self):
        """
        Test that the allowlist generation is invoked if the allowlist is enabled for a user on the list
        """
        with mock.patch(
            'lms.djangoapps.certificates.signals.generate_certificate.apply_async',
            return_value=None
        ) as mock_generate_certificate_apply_async:
            with mock.patch(
                'lms.djangoapps.certificates.signals.generate_allowlist_certificate_task',
                return_value=None
            ) as mock_generate_allowlist_task:
                CertificateWhitelistFactory(
                    user=self.user,
                    course_id=self.ip_course.id,
                    whitelist=True
                )

                fire_ungenerated_certificate_task(self.user, self.ip_course.id)
                mock_generate_certificate_apply_async.assert_not_called()
                mock_generate_allowlist_task.assert_called_with(self.user, self.ip_course.id)
Exemple #4
0
    def test_fire_task_allowlist_disabled(self):
        """
        Test that the normal logic is followed if the allowlist is disabled for a user on the list
        """
        with mock.patch(
                'lms.djangoapps.certificates.signals.generate_certificate.apply_async',
                return_value=None) as mock_generate_certificate_apply_async:
            with mock.patch(
                    'lms.djangoapps.certificates.signals.generate_allowlist_certificate_task',
                    return_value=None) as mock_generate_allowlist_task:
                CertificateWhitelistFactory(user=self.user,
                                            course_id=self.ip_course.id,
                                            whitelist=True)

                fire_ungenerated_certificate_task(self.user, self.ip_course.id)
                mock_generate_certificate_apply_async.assert_called_with(
                    countdown=CERTIFICATE_DELAY_SECONDS,
                    kwargs={
                        'student': six.text_type(self.user.id),
                        'course_key': six.text_type(self.ip_course.id),
                    })
                mock_generate_allowlist_task.assert_not_called()