Exemple #1
0
 def test_disabled_config(self):
     """With the config disabled, it shouldn't send an email"""
     self.default_config.enabled = False
     self.default_config.save()
     send_program_certificate_created_message(self.user.username,
                                              self.program_cert)
     self.assertEqual(0, len(mail.outbox))
Exemple #2
0
    def test_base_template(self):
        self._setup_program_and_program_cert('Radical Program')

        send_program_certificate_created_message(self.user.username,
                                                 self.program_cert)

        self._assert_email_contents()
Exemple #3
0
    def test_custom_email_template_alternative_program_type(self):
        self._setup_program_and_program_cert('Tubular Program')

        with self.settings(CUSTOM_COMPLETION_EMAIL_TEMPLATE_EXTRA=self.
                           _get_custom_completion_email_template_settings()):
            send_program_certificate_created_message(self.user.username,
                                                     self.program_cert)

        self._assert_email_contents()
Exemple #4
0
    def issue_credential(self,
                         credential,
                         username,
                         status=UserCredentialStatus.AWARDED,
                         attributes=None,
                         request=None):
        """
        Issue a Program Certificate to the user.

        This function is being overriden to provide functionality for sending
        an updated email to pathway partners

        This action is idempotent. If the user has already earned the
        credential, a new one WILL NOT be issued. The existing credential
        WILL be modified.

        Arguments:
            credential (AbstractCredential): Type of credential to issue.
            username (str): username of user for which credential required
            status (str): status of credential
            attributes (List[dict]): optional list of attributes that should be associated with the issued credential.
            request (HttpRequest): request object to build program record absolute uris

        Returns:
            UserCredential
        """
        user_credential, created = UserCredential.objects.update_or_create(
            username=username,
            credential_content_type=ContentType.objects.get_for_model(
                credential),
            credential_id=credential.id,
            defaults={
                "status": status,
            },
        )

        # Send an updated email to a pathway org only if the user has previously sent one
        # This function call should be moved into some type of task queue
        # once credentials has that functionality
        site_config = getattr(credential.site, "siteconfiguration", None)
        # Add a check to see if records_enabled is True for the site associated with
        # the credentials. If records is not enabled, we should not send this email
        if created and site_config and site_config.records_enabled:
            send_updated_emails_for_program(request, username, credential)

        # If this is a new ProgramCertificate and the `SEND_EMAIL_ON_PROGRAM_COMPLETION`
        # feature is enabled then let's send a congratulatory message to the learner
        if created and getattr(settings, "SEND_EMAIL_ON_PROGRAM_COMPLETION",
                               False):
            send_program_certificate_created_message(username, credential)

        self.set_credential_attributes(user_credential, attributes)

        return user_credential
Exemple #5
0
    def test_custom_email_template_program_uuid(self):
        """
        Test for the contents of a custom email template.
        """
        self._setup_program_and_program_cert('Excellent Program',
                                             self.FAKE_PROGRAM_UUID)

        with self.settings(CUSTOM_COMPLETION_EMAIL_TEMPLATE_EXTRA=self.
                           _get_custom_completion_email_template_settings()):
            send_program_certificate_created_message(self.user.username,
                                                     self.program_cert)

        self._assert_email_contents()
Exemple #6
0
    def test_send_email_exception_occurs(self):
        self._setup_program_and_program_cert("Radical Program")

        expected_messages = [
            "Sending Program completion email to learner with id [{}] in Program [{}]"
            .format(self.user.id, self.program.uuid),
            "Unable to send email to learner with id: [{}] for Program [{}]. Error occurred while attempting to "
            "format or send message: Error!".format(self.user.id,
                                                    self.program.uuid),
        ]

        with LogCapture() as log:
            with mock.patch("edx_ace.ace.send",
                            side_effect=Exception("Error!")):
                send_program_certificate_created_message(
                    self.user.username, self.program_cert)

        for index, message in enumerate(expected_messages):
            assert message in log.records[index].getMessage()
Exemple #7
0
 def test_retired_program(self):
     self.program.status = ProgramStatus.RETIRED.value
     self.program.save()
     send_program_certificate_created_message(self.user.username,
                                              self.program_cert)
     self.assertEqual(0, len(mail.outbox))