def test_updates_times(self, render_mock, address_mock):
     render_mock.return_value = ['<p>This is a test html email.</p>', 'This is a test text email.']
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     g_email(context={}, scheduled=datetime.min)
     tasks.SendUnsentScheduledEmails().delay()
     sent_email = Email.objects.filter(sent__isnull=False)
     self.assertEqual(sent_email.count(), 1)
示例#2
0
    def test_text_and_html_path(self):
        G(ContextRenderer,
          source=self.source,
          html_template_path='hi_template.html',
          text_template_path='hi_template.txt',
          rendering_style=self.rendering_style,
          context_hints={
              'entity': {
                  'app_name': 'entity',
                  'model_name': 'Entity',
              }
          })

        person = G(Entity, display_name='Swansonbot')
        event = G(Event, context={'entity': person.id}, source=self.source)
        email = g_email(context={'entity': person.id})
        email = g_email(event=event)

        url = reverse('entity_emailer.email', args=[email.view_uid])
        response = self.client.get(url)
        content = response.content
        if six.PY3:  # pragma: no cover
            content = content.decode('utf8')

        self.assertEqual(content, '<html>Hi Swansonbot</html>')
 def test_sends_all_scheduled_emails(self, render_mock, address_mock):
     render_mock.return_value = ['<p>This is a test html email.</p>', 'This is a test text email.']
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     g_email(context={}, scheduled=datetime.min)
     g_email(context={}, scheduled=datetime.min)
     tasks.SendUnsentScheduledEmails().delay()
     self.assertEqual(len(mail.outbox), 2)
 def test_sends_email_with_specified_from_address(self, render_mock, address_mock):
     render_mock.return_value = ['<p>This is a test html email.</p>', 'This is a test text email.']
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     from_address = '*****@*****.**'
     g_email(context={}, from_address=from_address, scheduled=datetime.min)
     tasks.SendUnsentScheduledEmails().delay()
     self.assertEqual(mail.outbox[0].from_email, from_address)
 def test_sends_all_scheduled_emails(self, render_mock, address_mock):
     render_mock.return_value = ['<p>This is a test html email.</p>', 'This is a test text email.']
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     g_email(context={}, scheduled=datetime.min)
     g_email(context={}, scheduled=datetime.min)
     EntityEmailerInterface.send_unsent_scheduled_emails()
     self.assertEqual(len(mail.outbox), 2)
示例#6
0
 def test_sends_no_sent_emails(self, render_mock, address_mock):
     render_mock.return_value = [
         '<p>This is a test html email.</p>', 'This is a test text email.'
     ]
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     g_email(context={}, scheduled=datetime.min, sent=datetime.utcnow())
     EntityEmailerInterface.send_unsent_scheduled_emails()
     self.assertEqual(len(mail.outbox), 0)
示例#7
0
 def test_updates_times(self, render_mock, address_mock):
     render_mock.return_value = [
         '<p>This is a test html email.</p>', 'This is a test text email.'
     ]
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     g_email(context={}, scheduled=datetime.min)
     EntityEmailerInterface.send_unsent_scheduled_emails()
     sent_email = Email.objects.filter(sent__isnull=False)
     self.assertEqual(sent_email.count(), 1)
示例#8
0
 def test_sends_email_with_specified_from_address(self, render_mock,
                                                  address_mock):
     render_mock.return_value = [
         '<p>This is a test html email.</p>', 'This is a test text email.'
     ]
     address_mock.return_value = ['*****@*****.**', '*****@*****.**']
     from_address = '*****@*****.**'
     g_email(context={}, from_address=from_address, scheduled=datetime.min)
     EntityEmailerInterface.send_unsent_scheduled_emails()
     self.assertEqual(mail.outbox[0].from_email, from_address)
示例#9
0
 def test_sends_all_scheduled_emails_no_email_addresses(
         self, render_mock, address_mock):
     render_mock.return_value = [
         '<p>This is a test html email.</p>', 'This is a test text email.'
     ]
     address_mock.return_value = []
     g_email(context={}, scheduled=datetime.min)
     g_email(context={}, scheduled=datetime.min)
     EntityEmailerInterface.send_unsent_scheduled_emails()
     self.assertEqual(len(mail.outbox), 0)
示例#10
0
 def test_returns_own_email(self):
     entity_1 = G(Entity, entity_meta={'email': '*****@*****.**'})
     entity_2 = G(Entity, entity_meta={'email': '*****@*****.**'})
     email = g_email(recipients=[entity_1, entity_2], context={})
     addresses = tasks.get_subscribed_email_addresses(email)
     expected_addresses = {u'*****@*****.**', u'*****@*****.**'}
     self.assertEqual(set(addresses), expected_addresses)
示例#11
0
    def test_get_emails_override_email_key_exclude_key(self):
        e1 = G(Entity, entity_meta={'email_address': '*****@*****.**'})
        e2 = G(Entity, entity_meta={'email_address': '*****@*****.**'})
        email = g_email(recipients=[e1, e2], context={})

        addresses = tasks.get_subscribed_email_addresses(email)
        self.assertEqual(set(addresses), set(['*****@*****.**', '*****@*****.**']))
示例#12
0
 def test_returns_own_email(self):
     entity_1 = G(Entity, entity_meta={'email': '*****@*****.**'})
     entity_2 = G(Entity, entity_meta={'email': '*****@*****.**'})
     email = g_email(recipients=[entity_1, entity_2], context={})
     addresses = get_subscribed_email_addresses(email)
     expected_addresses = {u'*****@*****.**', u'*****@*****.**'}
     self.assertEqual(set(addresses), expected_addresses)
    def test_get_emails_override_email_key(self):
        e1 = G(Entity, entity_meta={'email_address': '*****@*****.**', 'last_invite_time': 1000})
        e2 = G(Entity, entity_meta={'email_address': '*****@*****.**', 'last_invite_time': None})
        e3 = G(Entity, entity_meta={'email_address': '*****@*****.**', 'last_invite_time': False})
        email = g_email(recipients=[e1, e2, e3], context={})

        addresses = get_subscribed_email_addresses(email)
        self.assertEqual(set(addresses), set(['*****@*****.**']))
示例#14
0
    def test_get_emails_override_email_key_exclude_key(self):
        e1 = G(Entity, entity_meta={'email_address': '*****@*****.**'})
        e2 = G(Entity, entity_meta={'email_address': '*****@*****.**'})
        email = g_email(recipients=[e1, e2], context={})

        addresses = get_subscribed_email_addresses(email)
        self.assertEqual(set(addresses),
                         set(['*****@*****.**', '*****@*****.**']))
    def test_get_emails_default_settings(self):
        e1 = G(Entity, entity_meta={'email': '*****@*****.**'})
        e2 = G(Entity, entity_meta={'email': '*****@*****.**'})
        e3 = G(Entity, entity_meta={'email': ''})
        e4 = G(Entity, entity_meta={})
        email = g_email(recipients=[e1, e2, e3, e4], context={})

        addresses = get_subscribed_email_addresses(email)
        self.assertEqual(set(addresses), set(['*****@*****.**', '*****@*****.**']))
    def test_text_and_html_path(self):
        G(
            ContextRenderer, source=self.source,
            html_template_path='hi_template.html', text_template_path='hi_template.txt',
            rendering_style=self.rendering_style, context_hints={
                'entity': {
                    'app_name': 'entity',
                    'model_name': 'Entity',
                }
            })

        person = G(Entity, display_name='Swansonbot')
        event = G(Event, context={'entity': person.id}, source=self.source)
        email = g_email(context={'entity': person.id})
        email = g_email(event=event)

        url = reverse('entity_emailer.email', args=[email.view_uid])
        response = self.client.get(url)
        self.assertEqual(response.content, '<html>Hi Swansonbot</html>')
示例#17
0
    def test_get_emails_default_settings(self):
        e1 = G(Entity, entity_meta={'email': '*****@*****.**'})
        e2 = G(Entity, entity_meta={'email': '*****@*****.**'})
        e3 = G(Entity, entity_meta={'email': ''})
        e4 = G(Entity, entity_meta={})
        email = g_email(recipients=[e1, e2, e3, e4], context={})

        addresses = get_subscribed_email_addresses(email)
        self.assertEqual(set(addresses),
                         set(['*****@*****.**', '*****@*****.**']))
 def test_text_path(self):
     G(
         ContextRenderer, source=self.source, html_template_path='hi_template.txt',
         rendering_style=self.rendering_style, context_hints={
             'entity': {
                 'app_name': 'entity',
                 'model_name': 'Entity',
             }
         })
     person = G(Entity, display_name='Swansonbot')
     event = G(Event, context={'entity': person.id}, source=self.source)
     email = g_email(event=event)
     url = reverse('entity_emailer.email', args=[email.view_uid])
     response = self.client.get(url)
     content = response.content
     if six.PY3:  # pragma: no cover
         content = content.decode('utf8')
     self.assertEqual(content, 'Hi Swansonbot')
示例#19
0
    def test_get_emails_override_email_key(self):
        e1 = G(Entity,
               entity_meta={
                   'email_address': '*****@*****.**',
                   'last_invite_time': 1000
               })
        e2 = G(Entity,
               entity_meta={
                   'email_address': '*****@*****.**',
                   'last_invite_time': None
               })
        e3 = G(Entity,
               entity_meta={
                   'email_address': '*****@*****.**',
                   'last_invite_time': False
               })
        email = g_email(recipients=[e1, e2, e3], context={})

        addresses = get_subscribed_email_addresses(email)
        self.assertEqual(set(addresses), set(['*****@*****.**']))
示例#20
0
 def test_no_recipients(self):
     email = g_email(recipients=[], context={})
     addresses = tasks.get_subscribed_email_addresses(email)
     self.assertEqual(addresses, [])
示例#21
0
 def test_no_recipients(self):
     email = g_email(recipients=[], context={})
     addresses = get_subscribed_email_addresses(email)
     self.assertEqual(addresses, [])