Exemplo n.º 1
0
 def test_configure(self):
     for kw in ({
             'tpl_fn': 'mail/test1.html'
     }, {
             'lang': 'en'
     }, {
             'tz': 'Europe/London'
     }):
         t = RenderMailSender('mail/test1.html')
         t.send('*****@*****.**')
         self.assertIsNotNone(t._tpl)
         self.assertIsNotNone(t._render_cache)
         t.configure(**kw)
         self.assertIsNone(t._tpl)
         self.assertIsNone(t._render_cache)
     for kw in ({'request': 'Request'}, {'context': {'a': 1}}):
         t = RenderMailSender('mail/test1.html')
         t.send('*****@*****.**')
         self.assertIsNotNone(t._context_cache)
         self.assertIsNotNone(t._render_cache)
         t.configure(**kw)
         self.assertIsNone(t._context_cache)
         self.assertIsNone(t._render_cache)
     t = RenderMailSender('mail/test1.html')
     with self.assertRaises(AttributeError):
         t.configure(abracadabra=1)
Exemplo n.º 2
0
 def test_render_mail_with_lang(self):
     t = RenderMailSender('mail/test3.html')
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      settings.EMAIL_SUBJECT_PREFIX + 'Test subject 3')
     self.assertTrue(u'Phone number' in mail.outbox[0].body)
     mail.outbox = []
     t = RenderMailSender('mail/test3.html', lang='uk')
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      settings.EMAIL_SUBJECT_PREFIX + 'Test subject 3')
     self.assertTrue(u'Номер телефону' in mail.outbox[0].body)
Exemplo n.º 3
0
 def test_render_mail_context_proccessors_with_request(self):
     t = RenderMailSender('mail/test4.html', request=self.R())
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      settings.EMAIL_SUBJECT_PREFIX + 'Test subject 4')
     self.assertTrue('STATIC_CP_VALUE_OK' in mail.outbox[0].body)
Exemplo n.º 4
0
 def test_render_mail(self):
     t = RenderMailSender('mail/test1.html', context={
         'm': 'test',
     })
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      settings.EMAIL_SUBJECT_PREFIX + 'Test subject 1 test')
Exemplo n.º 5
0
 def test_render_mail_using_cache(self):
     t = RenderMailSender('mail/test1.html')
     self.assertIsNone(t._render_cache)
     self.assertIsNone(t._context_cache)
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertIsNotNone(t._render_cache)
     self.assertIsNotNone(t._context_cache)
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 2)
Exemplo n.º 6
0
 def test_render_mail_with_tz(self):
     now = timezone.now()
     t = RenderMailSender('mail/test2.html', context={'now': now})
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      settings.EMAIL_SUBJECT_PREFIX + 'Test subject 2')
     self.assertTrue(
         now.strftime('%Y.%m.%d %H:%M:%S') in mail.outbox[0].body)
     mail.outbox = []
     t = RenderMailSender('mail/test2.html',
                          context={'now': now},
                          tz='Europe/Warsaw')
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject,
                      settings.EMAIL_SUBJECT_PREFIX + 'Test subject 2')
     self.assertTrue(
         now.astimezone(pytz.timezone('Europe/Warsaw')).strftime(
             '%Y.%m.%d %H:%M:%S') in mail.outbox[0].body)
Exemplo n.º 7
0
 def handle(self, *args, **options):
     if not args:
         self.log('Please, pass the email list as args: '
                  'manage.py send_test_email [email protected] [email protected] ...', add_time=False)
         return
     m = RenderMailSender('dju_common/mail/test.html', lang=settings.LANGUAGE_CODE)
     for email in set(args):
         self.log('Send the test email to {email}... '.format(email=email), ending='')
         try:
             m.send(email)
             self.log('OK', add_time=False)
         except Exception, e:
             self.log('FAIL', add_time=False)
             self.log(traceback.format_exc(), add_time=False)
             raise e
Exemplo n.º 8
0
 def test_render_mail_and_url_tag(self):
     t = RenderMailSender('mail/test5.html')
     t.send('*****@*****.**')
     self.assertEqual(len(mail.outbox), 1)
     self.assertIn(reverse('test_page'), mail.outbox[0].body)
Exemplo n.º 9
0
 def test_render_mail_render_error(self):
     for i in range(1, 4):
         t = RenderMailSender('mail/test_invalid_{}.html'.format(i))
         with self.assertRaises(t.TemplateEmailTagNotFound):
             t.send('testerror{}@mail.com'.format(i))