Exemplo n.º 1
0
    def test_signal_received(self, mock_is_learner_issuance_enabled, mock_task):  # pylint: disable=unused-argument
        """
        Ensures the receiver function is invoked when COURSE_CERT_AWARDED is
        sent.

        Suboptimal: because we cannot mock the receiver function itself (due
        to the way django signals work), we mock a configuration call that is
        known to take place inside the function.
        """
        COURSE_CERT_AWARDED.send(**self.signal_kwargs)
        self.assertEqual(mock_is_learner_issuance_enabled.call_count, 1)
Exemplo n.º 2
0
 def save(self, *args, **kwargs):
     """
     After the base save() method finishes, fire the COURSE_CERT_AWARDED
     signal iff we are saving a record of a learner passing the course.
     """
     super(GeneratedCertificate, self).save(*args, **kwargs)
     if CertificateStatuses.is_passing_status(self.status):
         COURSE_CERT_AWARDED.send_robust(
             sender=self.__class__,
             user=self.user,
             course_key=self.course_id,
             mode=self.mode,
             status=self.status,
         )
Exemplo n.º 3
0
 def save(self, *args, **kwargs):
     """
     After the base save() method finishes, fire the COURSE_CERT_AWARDED
     signal iff we are saving a record of a learner passing the course.
     """
     super(GeneratedCertificate, self).save(*args, **kwargs)
     if CertificateStatuses.is_passing_status(self.status):
         COURSE_CERT_AWARDED.send_robust(
             sender=self.__class__,
             user=self.user,
             course_key=self.course_id,
             mode=self.mode,
             status=self.status,
         )
Exemplo n.º 4
0
    def save(self, *args, **kwargs):
        """
        After the base save() method finishes, fire the COURSE_CERT_AWARDED
        signal iff we have stored a record of a learner passing the course.

        The learner is assumed to have passed the course if certificate status
        is either 'generating' or 'downloadable'.
        """
        super(GeneratedCertificate, self).save(*args, **kwargs)
        if self.status in [CertificateStatuses.generating, CertificateStatuses.downloadable]:
            COURSE_CERT_AWARDED.send_robust(
                sender=self.__class__,
                user=self.user,
                course_key=self.course_id,
                mode=self.mode,
                status=self.status,
            )
Exemplo n.º 5
0
 def save(self, *args, **kwargs):  # pylint: disable=signature-differs
     """
     After the base save() method finishes, fire the COURSE_CERT_AWARDED
     signal iff we are saving a record of a learner passing the course.
     As well as the COURSE_CERT_CHANGED for any save event.
     """
     super().save(*args, **kwargs)
     COURSE_CERT_CHANGED.send_robust(
         sender=self.__class__,
         user=self.user,
         course_key=self.course_id,
         mode=self.mode,
         status=self.status,
     )
     if CertificateStatuses.is_passing_status(self.status):
         COURSE_CERT_AWARDED.send_robust(
             sender=self.__class__,
             user=self.user,
             course_key=self.course_id,
             mode=self.mode,
             status=self.status,
         )
Exemplo n.º 6
0
    def save(self, *args, **kwargs):  # pylint: disable=signature-differs
        """
        After the base save() method finishes, fire the COURSE_CERT_CHANGED signal. If the learner is currently passing
        the course we also fire the COURSE_CERT_AWARDED signal.

        The COURSE_CERT_CHANGED signal helps determine if a Course Certificate can be awarded to a learner in the
        Credentials IDA.

        The COURSE_CERT_AWARDED signal helps determine if a Program Certificate can be awarded to a learner in the
        Credentials IDA.
        """
        super().save(*args, **kwargs)
        COURSE_CERT_CHANGED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )

        # .. event_implemented_name: CERTIFICATE_CHANGED
        CERTIFICATE_CHANGED.send_event(certificate=CertificateData(
            user=UserData(
                pii=UserPersonalData(
                    username=self.user.username,
                    email=self.user.email,
                    name=self.user.profile.name,
                ),
                id=self.user.id,
                is_active=self.user.is_active,
            ),
            course=CourseData(course_key=self.course_id, ),
            mode=self.mode,
            grade=self.grade,
            current_status=self.status,
            download_url=self.download_url,
            name=self.name,
        ))

        if CertificateStatuses.is_passing_status(self.status):
            COURSE_CERT_AWARDED.send_robust(
                sender=self.__class__,
                user=self.user,
                course_key=self.course_id,
                mode=self.mode,
                status=self.status,
            )

            # .. event_implemented_name: CERTIFICATE_CREATED
            CERTIFICATE_CREATED.send_event(certificate=CertificateData(
                user=UserData(
                    pii=UserPersonalData(
                        username=self.user.username,
                        email=self.user.email,
                        name=self.user.profile.name,
                    ),
                    id=self.user.id,
                    is_active=self.user.is_active,
                ),
                course=CourseData(course_key=self.course_id, ),
                mode=self.mode,
                grade=self.grade,
                current_status=self.status,
                download_url=self.download_url,
                name=self.name,
            ))