Esempio n. 1
0
    def test_send_bulk_mail_data_properly_sent(self):
        """Verifies that the data sent in send_bulk_mail is correct
           for each user in the recipient list.
        """
        mailgun_api = self.swap(feconf, 'MAILGUN_API_KEY', 'api')
        mailgun_domain = self.swap(feconf, 'MAILGUN_DOMAIN_NAME', 'domain')
        allow_emailing = self.swap(feconf, 'CAN_SEND_EMAILS', True)
        recipients = [feconf.ADMIN_EMAIL_ADDRESS]

        # Data that we expect to have been sent in the post_to_mailgun().
        expected = ({
            'from': feconf.SYSTEM_EMAIL_ADDRESS,
            'to': recipients,
            'subject': 'subject',
            'text': 'body',
            'html': 'html',
            'recipient-variables': '{}'
        })

        # Lambda function, will replace post_to_mailgun().
        req_post_lambda = (
            lambda data=None: self.assertDictContainsSubset(expected, data))
        post_request = self.swap(mailgun_email_services, 'post_to_mailgun',
                                 req_post_lambda)

        with mailgun_api, mailgun_domain, post_request, allow_emailing:
            mailgun_email_services.send_bulk_mail(feconf.SYSTEM_EMAIL_ADDRESS,
                                                  recipients, 'subject',
                                                  'body', 'html')
Esempio n. 2
0
 def test_send_bulk_mail_raises_exception_for_missing_api_key(self):
     """Test that send_bulk_mail raises exception for missing
         mailgun api key.
     """
     mailgun_api_exception = (self.assertRaisesRegexp(
         Exception, 'Mailgun API key is not available.'))
     allow_emailing = self.swap(feconf, 'CAN_SEND_EMAILS', True)
     with mailgun_api_exception, allow_emailing:
         mailgun_email_services.send_bulk_mail(feconf.SYSTEM_EMAIL_ADDRESS,
                                               [feconf.ADMIN_EMAIL_ADDRESS],
                                               'subject', 'body', 'html')
Esempio n. 3
0
 def test_send_bulk_mail_exception_for_invalid_permissions(self):
     """Tests the send_bulk_mail exception raised for invalid user
        permissions.
     """
     send_email_exception = (self.assertRaisesRegexp(
         Exception, 'This app cannot send emails to users.'))
     mailgun_api = self.swap(feconf, 'MAILGUN_API_KEY', 'api')
     mailgun_domain = self.swap(feconf, 'MAILGUN_DOMAIN_NAME', 'domain')
     with mailgun_api, mailgun_domain, send_email_exception:
         mailgun_email_services.send_bulk_mail(feconf.SYSTEM_EMAIL_ADDRESS,
                                               [feconf.ADMIN_EMAIL_ADDRESS],
                                               'subject', 'body', 'html')
Esempio n. 4
0
 def test_send_bulk_mail_raises_exception_for_missing_domain_name(self):
     """Tests the missing Mailgun domain name exception for
         send_bulk_mail.
     """
     mailgun_api = self.swap(feconf, 'MAILGUN_API_KEY', 'api')
     allow_emailing = self.swap(feconf, 'CAN_SEND_EMAILS', True)
     mailgun_domain_name_exception = (self.assertRaisesRegexp(
         Exception, 'Mailgun domain name is not set.'))
     with mailgun_api, mailgun_domain_name_exception, allow_emailing:
         mailgun_email_services.send_bulk_mail(feconf.SYSTEM_EMAIL_ADDRESS,
                                               [feconf.ADMIN_EMAIL_ADDRESS],
                                               'subject', 'body', 'html')