Example #1
0
 def test_basic_template(self):
     mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir])
     content = mailer.render(
         'simple_template.html',
     )
     self.assertEqual(content.subject, "My Subject")
     self.assertEqual(content.html_body, "HTML stuff")
     self.assertEqual(content.text_body, "Text stuff")
 def test_delivery_engine_not_installed(self):
     """
     Tests to make sure DeliveryEngineNotInstalled is raised
     :return:
     """
     mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir])
     self.assertRaises(templatemail.DeliveryEngineNotInstalled,
                       mailer.send_email,
                       to_addresses=['*****@*****.**'],
                       from_address='*****@*****.**',
                       template_name='simple_template.html')
    def test_mailgun_sending_failure(self):
        engine = templatemail.engines.mailgun.MailgunDeliveryEngine(
            api_key='foobar', domain_name='spam.eggs')
        engine._requests.post = Mock(return_value=Mock(status_code=401))

        mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir],
                                           delivery_engine=engine)
        self.assertRaises(templatemail.DeliveryNotMade,
                          mailer.send_email,
                          to_addresses=['*****@*****.**'],
                          from_address='*****@*****.**',
                          template_name='simple_template.html')
Example #4
0
 def _test_sending(self, engine):
     mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir], delivery_engine=engine)
     result = mailer.send_email(
         to_addresses=['*****@*****.**'],
         from_address='*****@*****.**',
         template_name='mailgun-transactional/alert.html',
         subject='You are over the number of widgets',
         signature='--The Team',
         action_link="http://localhost:8080/upgrade",
         action_text="Upgrade Now",
         warning_text="You are over the number of widgets on your current plan",
         details="Upgrade now and you can get way, way more widgets.\nNo I'm serious, like, a ton more.",
         footer='Sent by the Acme Corporation'
     )
Example #5
0
    def test_render_alert_email(self):
        mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir])
        content = mailer.render(
            'mailgun-transactional/alert.html',
            subject='You are over the number of widgets',
            signature='--The Team',
            action_link="http://localhost:8080/upgrade",
            action_text="Upgrade Now",
            warning_text="You are over the number of widgets on your current plan",
            details="Upgrade now and you can get way, way more widgets.\nNo I'm serious, like, a ton more.",
            footer='Sent by the Acme Corporation'
        )
        self.assertEqual(content.subject, "You are over the number of widgets")
        self.assertIn("--The Team", content.text_body)
        self.assertIn("--The Team", content.html_body)

        self._open_content_rendering_in_browser(content)
Example #6
0
    def test_render_action_email(self):
        mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir])
        content = mailer.render(
            'mailgun-transactional/action.html',
            subject="Did You Forget Your Password?",
            meta_name='Confirm Email',
            leadin='Please confirm your email address by clicking the link below.',
            explanation='We may need to send you critical information about our service and it is important that we have an accurate email address.',
            action_link='https://localhost:8080/forgot-password/click-me',
            action_text="Reset your password",
            signature='--The Team',
            footer='You are getting this message because someone (presumably you) clicked on Forgot Password on our site.'
        )
        self.assertEqual(content.subject, "Did You Forget Your Password?")
        self.assertIn("--The Team", content.text_body)
        self.assertIn("--The Team", content.html_body)

        self._open_content_rendering_in_browser(content)
    def test_render_billing_email(self):
        mailer = templatemail.TemplateMail(template_dirs=[_test_template_dir])
        content = mailer.render(
            'mailgun-transactional/billing.html',
            invoice_to="Lee Munroe\nInvoice #12345\nJune 01 2014",
            services=[('Consulting', '$55'), ('Cheese Making', '$500')],
            total_text='Total',
            total_price='$555',
            view_link='http://localhost:8080/invoice',
            view_text='View your invoice online',
            subject="Your invoice is paid",
            title="$33.98 Paid",
            subtitle='Thank you for using Acme.',
            signature='--The Team',
            footer='Sent by the Acme Corporation')
        self.assertEqual(content.subject, "Your invoice is paid")
        self.assertIn("--The Team", content.text_body)
        self.assertIn("--The Team", content.html_body)

        self._open_content_rendering_in_browser(content)