Exemple #1
0
 def setUp(self):
     super(CertificateServiceTests, self).setUp()
     self.service = CertificateService()
     self.course = CourseFactory()
     self.user = UserFactory()
     self.user_id = self.user.id
     self.course_id = self.course.id
     GeneratedCertificateFactory.create(
         status=CertificateStatuses.downloadable,
         user=self.user,
         course_id=self.course.id,
         grade=1.0)
Exemple #2
0
 def setUp(self):
     super(CertificateServiceTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.service = CertificateService()
     self.course = CourseFactory()
     self.user = UserFactory()
     self.user_id = self.user.id
     self.course_id = self.course.id  # lint-amnesty, pylint: disable=no-member
     GeneratedCertificateFactory.create(
         status=CertificateStatuses.downloadable,
         user=self.user,
         course_id=self.course.id,  # lint-amnesty, pylint: disable=no-member
         grade=1.0)
Exemple #3
0
 def setUp(self):
     super().setUp()
     self.service = CertificateService()
     self.course = CourseFactory()
     self.user = UserFactory()
     self.user_id = self.user.id
     self.course_id = self.course.id  # pylint: disable=no-member
     GeneratedCertificateFactory.create(
         status=CertificateStatuses.downloadable,
         user=self.user,
         course_id=self.course.id,  # pylint: disable=no-member
         grade=1.0)
Exemple #4
0
class CertificateServiceTests(ModuleStoreTestCase):
    """
    Tests for the Certificate service
    """
    shard = 4

    def setUp(self):
        super(CertificateServiceTests, self).setUp()
        self.service = CertificateService()
        self.course = CourseFactory()
        self.user = UserFactory()
        self.user_id = self.user.id
        self.course_id = self.course.id
        GeneratedCertificateFactory.create(
            status=CertificateStatuses.downloadable,
            user=self.user,
            course_id=self.course.id,
            grade=1.0
        )

    def generated_certificate_to_dict(self, generated_certificate):
        """
        Converts a Generated Certificate instance to a Python dictionary
        """
        return {
            'verify_uuid': generated_certificate.verify_uuid,
            'download_uuid': generated_certificate.download_uuid,
            'download_url': generated_certificate.download_url,
            'grade': generated_certificate.grade,
            'status': generated_certificate.status
        }

    def test_invalidate_certificate(self):
        """
        Verify that CertificateService invalidates the user certificate
        """
        self.service.invalidate_certificate(self.user_id, self.course_id)
        invalid_generated_certificate = GeneratedCertificate.objects.get(
            user=self.user_id,
            course_id=self.course_id
        )
        self.assertDictEqual(
            self.generated_certificate_to_dict(invalid_generated_certificate),
            {
                'verify_uuid': '',
                'download_uuid': '',
                'download_url': '',
                'grade': '',
                'status': CertificateStatuses.unavailable
            }
        )
Exemple #5
0
 def ready(self):
     """
     Connect handlers to signals.
     """
     # Can't import models at module level in AppConfigs, and models get
     # included from the signal handlers
     from lms.djangoapps.certificates import signals  # pylint: disable=unused-import
     if settings.FEATURES.get('ENABLE_SPECIAL_EXAMS'):
         from lms.djangoapps.certificates.services import CertificateService
         set_runtime_service('certificates', CertificateService())
Exemple #6
0
 def setUp(self):
     super(CertificateServiceTests, self).setUp()
     self.service = CertificateService()
     self.course = CourseFactory()
     self.user = UserFactory()
     self.user_id = self.user.id
     self.course_id = self.course.id
     GeneratedCertificateFactory.create(
         status=CertificateStatuses.downloadable,
         user=self.user,
         course_id=self.course.id,
         grade=1.0
     )
Exemple #7
0
class CertificateServiceTests(ModuleStoreTestCase):
    """
    Tests for the Certificate service
    """
    def setUp(self):
        super().setUp()
        self.service = CertificateService()
        self.course = CourseFactory()
        self.course_overview = CourseOverviewFactory.create(id=self.course.id)
        self.user = UserFactory()
        self.user_id = self.user.id
        self.course_id = self.course.id  # pylint: disable=no-member
        GeneratedCertificateFactory.create(
            status=CertificateStatuses.downloadable,
            user=self.user,
            course_id=self.course.id,  # pylint: disable=no-member
            grade=1.0)

    def generated_certificate_to_dict(self, generated_certificate):
        """
        Converts a Generated Certificate instance to a Python dictionary
        """
        return {
            'verify_uuid': generated_certificate.verify_uuid,
            'download_uuid': generated_certificate.download_uuid,
            'download_url': generated_certificate.download_url,
            'grade': generated_certificate.grade,
            'status': generated_certificate.status
        }

    def test_invalidate_certificate(self):
        """
        Verify that CertificateService invalidates the user certificate
        """
        success = self.service.invalidate_certificate(self.user_id,
                                                      self.course_id)
        assert success

        invalid_generated_certificate = GeneratedCertificate.objects.get(
            user=self.user_id, course_id=self.course_id)
        self.assertDictEqual(
            self.generated_certificate_to_dict(invalid_generated_certificate),
            {
                'verify_uuid': invalid_generated_certificate.verify_uuid,
                'download_uuid': '',
                'download_url': '',
                'grade': '',
                'status': CertificateStatuses.unavailable
            })

    def test_invalidate_certificate_allowlist(self):
        """
        Verify that CertificateService does not invalidate the certificate if it is allowlisted
        """
        u = UserFactory.create()
        c = CourseFactory()
        course_key = c.id  # pylint: disable=no-member
        GeneratedCertificateFactory.create(
            status=CertificateStatuses.downloadable,
            user=u,
            course_id=course_key,
            grade=1.0)
        CertificateAllowlistFactory(user=u, course_id=course_key)
        success = self.service.invalidate_certificate(u.id, course_key)
        assert not success

        cert = GeneratedCertificate.objects.get(user=u.id,
                                                course_id=course_key)
        assert cert.status == CertificateStatuses.downloadable
class CertificateServiceTests(ModuleStoreTestCase):
    """
    Tests for the Certificate service
    """
    def setUp(self):
        super(CertificateServiceTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
        self.service = CertificateService()
        self.course = CourseFactory()
        self.user = UserFactory()
        self.user_id = self.user.id
        self.course_id = self.course.id  # lint-amnesty, pylint: disable=no-member
        GeneratedCertificateFactory.create(
            status=CertificateStatuses.downloadable,
            user=self.user,
            course_id=self.course.id,  # lint-amnesty, pylint: disable=no-member
            grade=1.0)

    def generated_certificate_to_dict(self, generated_certificate):
        """
        Converts a Generated Certificate instance to a Python dictionary
        """
        return {
            'verify_uuid': generated_certificate.verify_uuid,
            'download_uuid': generated_certificate.download_uuid,
            'download_url': generated_certificate.download_url,
            'grade': generated_certificate.grade,
            'status': generated_certificate.status
        }

    def test_invalidate_certificate(self):
        """
        Verify that CertificateService invalidates the user certificate
        """
        success = self.service.invalidate_certificate(self.user_id,
                                                      self.course_id)
        self.assertTrue(success)

        invalid_generated_certificate = GeneratedCertificate.objects.get(
            user=self.user_id, course_id=self.course_id)
        self.assertDictEqual(
            self.generated_certificate_to_dict(invalid_generated_certificate),
            {
                'verify_uuid': '',
                'download_uuid': '',
                'download_url': '',
                'grade': '',
                'status': CertificateStatuses.unavailable
            })

    @override_waffle_flag(CERTIFICATES_USE_ALLOWLIST, active=True)
    def test_invalidate_certificate_allowlist(self):
        """
        Verify that CertificateService does not invalidate the certificate if it is allowlisted
        """
        u = UserFactory.create()
        c = CourseFactory()
        course_key = c.id  # pylint: disable=no-member
        GeneratedCertificateFactory.create(
            status=CertificateStatuses.downloadable,
            user=u,
            course_id=course_key,
            grade=1.0)
        CertificateWhitelistFactory(user=u, course_id=course_key)
        success = self.service.invalidate_certificate(u.id, course_key)
        self.assertFalse(success)

        cert = GeneratedCertificate.objects.get(user=u.id,
                                                course_id=course_key)
        self.assertEqual(cert.status, CertificateStatuses.downloadable)