Exemplo n.º 1
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)
     tasks.SendUnsentScheduledEmails().delay()
     sent_email = Email.objects.filter(sent__isnull=False)
     self.assertEqual(sent_email.count(), 1)
Exemplo n.º 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>')
Exemplo n.º 3
0
 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)
Exemplo n.º 4
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)
     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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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(['*****@*****.**', '*****@*****.**']))
Exemplo n.º 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(['*****@*****.**']))
Exemplo n.º 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>')
Exemplo n.º 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(['*****@*****.**', '*****@*****.**']))
Exemplo n.º 18
0
 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')
Exemplo n.º 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(['*****@*****.**']))
Exemplo n.º 20
0
 def test_no_recipients(self):
     email = g_email(recipients=[], context={})
     addresses = tasks.get_subscribed_email_addresses(email)
     self.assertEqual(addresses, [])
Exemplo n.º 21
0
 def test_no_recipients(self):
     email = g_email(recipients=[], context={})
     addresses = get_subscribed_email_addresses(email)
     self.assertEqual(addresses, [])