示例#1
0
    def test_basic_only_following_true_subscription(self):
        source = G(Source)
        e = G(Entity)
        se = G(Entity)
        G(EntityRelationship, sub_entity=e, super_entity=se)
        other_e = G(Entity)

        G(Subscription,
          entity=e,
          source=source,
          medium=self.email_medium,
          only_following=True)
        G(Subscription,
          entity=other_e,
          source=source,
          medium=self.email_medium,
          only_following=True)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=se)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        # Since the other_e entity does not follow the se entity, only the e entity receives an email
        self.assertEquals(set(email.recipients.all()), set([e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
示例#2
0
    def test_basic_only_following_false_group_subscription_with_unsubscribed(
            self):
        source = G(Source)
        ek = G(EntityKind)
        e = G(Entity, entity_kind=ek)
        se = G(Entity)
        G(EntityRelationship, sub_entity=e, super_entity=se)
        other_e = G(Entity, entity_kind=ek)
        G(EntityRelationship, sub_entity=other_e, super_entity=se)

        G(Subscription,
          entity=se,
          sub_entity_kind=ek,
          source=source,
          medium=self.email_medium,
          only_following=False)
        G(Unsubscription, entity=e, source=source, medium=self.email_medium)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(set(email.recipients.all()), set([other_e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
 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)
 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)
 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)
    def test_basic_only_following_false_group_subscription_with_unsubscribed(self):
        source = G(Source)
        ek = G(EntityKind)
        e = G(Entity, entity_kind=ek)
        se = G(Entity)
        G(EntityRelationship, sub_entity=e, super_entity=se)
        other_e = G(Entity, entity_kind=ek)
        G(EntityRelationship, sub_entity=other_e, super_entity=se)

        G(Subscription, entity=se, sub_entity_kind=ek, source=source, medium=self.email_medium, only_following=False)
        G(Unsubscription, entity=e, source=source, medium=self.email_medium)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(set(email.recipients.all()), set([other_e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
示例#7
0
    def test_multiple_events_only_following_true(self):
        source = G(Source)
        e = G(Entity)
        other_e = G(Entity)

        G(Subscription,
          entity=e,
          source=source,
          medium=self.email_medium,
          only_following=True)
        G(Subscription,
          entity=other_e,
          source=source,
          medium=self.email_medium,
          only_following=True)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        G(Event, source=source, context=email_context)
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(set(email.recipients.all()), set([e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
示例#8
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)
示例#9
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)
示例#10
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)
示例#11
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)
    def test_default_from_email(self):
        # settings.DEFAULT_FROM_EMAIL is already set to [email protected]
        source = G(Source)
        e = G(Entity)
        G(Subscription, entity=e, source=source, medium=self.email_medium, only_following=False, sub_entity_kind=None)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()
        email = Email.objects.get()

        self.assertEqual(email.from_address, '*****@*****.**')
    def test_custom_from_email(self):
        source = G(Source)
        e = G(Entity)
        G(Subscription, entity=e, source=source, medium=self.email_medium, only_following=False, sub_entity_kind=None)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
            'from_address': '*****@*****.**'
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()
        email = Email.objects.get()

        self.assertEqual(email.from_address, '*****@*****.**')
    def test_basic_only_following_false_subscription(self):
        source = G(Source)
        e = G(Entity)
        G(Subscription, entity=e, source=source, medium=self.email_medium, only_following=False, sub_entity_kind=None)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(list(email.recipients.all()), [e])
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
    def test_custom_from_email(self):
        source = G(Source)
        e = G(Entity)
        G(Subscription,
          entity=e,
          source=source,
          medium=self.email_medium,
          only_following=False,
          sub_entity_kind=None)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
            'from_address': '*****@*****.**'
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()
        email = Email.objects.get()

        self.assertEqual(email.from_address, '*****@*****.**')
    def test_default_from_email(self):
        # settings.DEFAULT_FROM_EMAIL is already set to [email protected]
        source = G(Source)
        e = G(Entity)
        G(Subscription,
          entity=e,
          source=source,
          medium=self.email_medium,
          only_following=False,
          sub_entity_kind=None)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()
        email = Email.objects.get()

        self.assertEqual(email.from_address, '*****@*****.**')
    def test_multiple_events_only_following_true(self):
        source = G(Source)
        e = G(Entity)
        other_e = G(Entity)

        G(Subscription, entity=e, source=source, medium=self.email_medium, only_following=True)
        G(Subscription, entity=other_e, source=source, medium=self.email_medium, only_following=True)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        G(Event, source=source, context=email_context)
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(set(email.recipients.all()), set([e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
示例#18
0
    def test_basic_only_following_false_subscription(self):
        source = G(Source)
        e = G(Entity)
        G(Subscription,
          entity=e,
          source=source,
          medium=self.email_medium,
          only_following=False,
          sub_entity_kind=None)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=e)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        self.assertEquals(list(email.recipients.all()), [e])
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
    def test_basic_only_following_true_subscription(self):
        source = G(Source)
        e = G(Entity)
        se = G(Entity)
        G(EntityRelationship, sub_entity=e, super_entity=se)
        other_e = G(Entity)

        G(Subscription, entity=e, source=source, medium=self.email_medium, only_following=True)
        G(Subscription, entity=other_e, source=source, medium=self.email_medium, only_following=True)
        email_context = {
            'entity_emailer_template': 'template',
            'entity_emailer_subject': 'hi',
        }
        event = G(Event, source=source, context=email_context)
        G(EventActor, event=event, entity=se)

        EntityEmailerInterface.convert_events_to_emails()

        email = Email.objects.get()
        # Since the other_e entity does not follow the se entity, only the e entity receives an email
        self.assertEquals(set(email.recipients.all()), set([e]))
        self.assertEquals(email.event.context, email_context)
        self.assertEquals(email.subject, '')
        self.assertEquals(email.scheduled, datetime(2013, 1, 2))
示例#20
0
 def test_no_subscriptions(self):
     G(Event, context={})
     EntityEmailerInterface.convert_events_to_emails()
     self.assertFalse(Email.objects.exists())
示例#21
0
 def test_no_events(self):
     EntityEmailerInterface.convert_events_to_emails()
     self.assertFalse(Email.objects.exists())
 def test_no_events(self):
     EntityEmailerInterface.convert_events_to_emails()
     self.assertFalse(Email.objects.exists())
 def test_no_subscriptions(self):
     G(Event, context={})
     EntityEmailerInterface.convert_events_to_emails()
     self.assertFalse(Email.objects.exists())