Exemple #1
0
 def test_clean_address(self):
     optout = OptOutFactory(origin=OptOut.BY_WEB)
     envelope = self.mk_envelope(b'', recipients=[optout.address])
     envelope.client = {'auth': (self.smtp_application.username, None)}
     envelope.user = self.user
     identifier.Add().apply(envelope)
     bounces.Check().apply(envelope)
Exemple #2
0
    def test_optout_send(self):
        """
        Check that previous optouts from different
        category are ignored in current category.
        """
        # A prev_message, in different category, with an optout
        old_category = CategoryFactory(author=self.user)
        old_message = MessageFactory(author=self.user, category=old_category)
        dark_mail = MailFactory(message=old_message)
        OptOutFactory(
            author=dark_mail.message.author,
            category=dark_mail.message.category,
            identifier=dark_mail.identifier,
            address=dark_mail.recipient,
            origin=OptOut.BY_WEB)

        # A message, in same category
        new_category = CategoryFactory(author=self.user)
        new_message = MessageFactory(author=self.user, category=new_category)
        MailFactory(message=new_message, recipient=dark_mail.recipient)
        good_mail = MailFactory(message=new_message)

        self.assertEqual(
            set(list(new_message.willsend_addresses())),
            set([dark_mail.recipient, good_mail.recipient]))
        self.assertEqual(list(new_message.willnotsend_addresses()), [])
Exemple #3
0
 def test_bounce(self):
     optout = OptOutFactory(origin=OptOut.BY_BOUNCE)
     envelope = self.mk_envelope(b'', recipients=[optout.address])
     envelope.client = {'auth': (self.smtp_application.username, None)}
     envelope.user = self.user
     identifier.Add().apply(envelope)
     with self.assertRaises(QueueError):
         bounces.Check().apply(envelope)
    def test_notify_optout_by_bounce(self):
        mail = MailFactory(message=self.message)
        mail.message.author.organization.settings.notify_optouts = True
        mail.message.author.organization.settings.save()
        OptOutFactory(identifier=mail.identifier,
                      address=mail.recipient,
                      origin=OptOut.BY_BOUNCE)

        self.assertEqual(len(django_mail.outbox), 0)
Exemple #5
0
    def test_legit_some_optout_override(self):
        mail = self.message.mails.first()
        OptOutFactory(author=self.message.author,
                      category=self.message.category,
                      identifier=mail.identifier,
                      address=mail.recipient)

        legit_objs = set(
            self.message.mails.legit_for(self.message, include_optouts=True))
        all_objs = set(self.message.mails.all())

        self.assertEqual(legit_objs, all_objs)
Exemple #6
0
    def test_legit_some_optout(self):
        mail = self.message.mails.first()
        OptOutFactory(author=self.message.author,
                      category=self.message.category,
                      identifier=mail.identifier,
                      address=mail.recipient)

        legit_objs = set(self.message.mails.legit_for(self.message))
        all_objs = set(self.message.mails.all())

        self.assertIn(mail, all_objs)
        self.assertNotIn(mail, legit_objs)
    def test_notify_optout(self):
        mail = MailFactory(message=self.message)
        mail.message.author.organization.settings.notify_optouts = True
        mail.message.author.organization.settings.save()
        OptOutFactory(author=mail.message.author,
                      category=mail.message.category,
                      identifier=mail.identifier,
                      address=mail.recipient,
                      origin=OptOut.BY_WEB)

        first_mail = django_mail.outbox[0]

        self.assertIn('no-reply', first_mail.from_email)
Exemple #8
0
    def test_get_organization(self):
        """
        Check that all the category app define a get_organization() method
        """
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)
        optout = OptOutFactory(author=user,
                               category=message.category,
                               identifier=mail.identifier,
                               address=mail.recipient)
        klasses = [
            user.organization, message,
            mail.statuses.first(), mail, optout
        ]

        for obj in klasses:
            self.assertEqual(obj.get_organization().pk, user.organization.pk)
Exemple #9
0
    def test_legit_some_bounce_optout(self):
        # Change the optout type to bounce
        mail = self.message.mails.filter(curstatus='bounced').first()
        opt_out = OptOutFactory(identifier=mail.identifier,
                                address=mail.recipient,
                                origin=OptOut.BY_BOUNCE)

        message = MessageFactory(author=self.user)

        # add a mail coresponding to an optout on a previous message
        # jane has two reasons not to receive the mail :
        # bounce-optout+regular-optout
        MailFactory(recipient=mail.recipient, message=message)
        legit_objs = set(
            self.message.mails.legit_for(self.message, include_optouts=True))
        all_objs = set(self.message.mails.all())

        self.assertNotEqual(legit_objs, all_objs)
Exemple #10
0
    def test_optout_count(self):
        category = CategoryFactory(author=self.user)
        message = MessageFactory(author=self.user, category=category)

        cases = [
            ('*****@*****.**', OptOut.BY_WEB),
            ('*****@*****.**', OptOut.BY_FBL),
            ('*****@*****.**', OptOut.BY_BOUNCE),
            ('*****@*****.**', OptOut.BY_ABUSE),
            ('*****@*****.**', OptOut.BY_ABUSE)]
        for addr, origin in cases:
            mail = MailFactory(message=message, recipient=addr)
            OptOutFactory(
                identifier=mail.identifier,
                address=mail.recipient,
                origin=origin)

        res = OptOut.objects.count_by_origin()
        self.assertEqual(
            res,
            {'mail': 0, 'abuse': 2, 'feedback-loop': 1, 'bounce': 1, 'web': 1})
Exemple #11
0
    def test_fire_message_handles_optouted(self):
        """
        Checks that an ignored recipient for cause of previous optout on its
        address will  put the Mail in IGNORED state, and will not prevent the
        other mail to reach its SENDING state and the Message to complete.
        """
        mail = MailFactory(message=self.message)
        OptOutFactory(author=self.message.author,
                      category=self.message.category,
                      identifier=mail.identifier,
                      address=mail.recipient)

        # A prev message with same recipient had an optout
        message = MessageFactory(author=self.user)
        mail_ok = MailFactory(message=message)
        mail_optouted = MailFactory(message=message, recipient=mail.recipient)

        message.status = 'sending'
        message.author.organization.settings.notify_message_status = False
        message.save()  # Fires the message

        self.assertEqual(
            message.mails.filter(curstatus=MailStatus.SENDING).count(), 1)
        self.assertEqual(
            message.mails.filter(curstatus=MailStatus.DELIVERED).count(), 0)
        self.assertEqual(
            Mail.objects.get(pk=mail_optouted.pk).curstatus,
            MailStatus.IGNORED)

        handle_dsn(
            'To: {}'.format(mail_ok.envelope_from), {
                'Final-Recipient': mail_ok.recipient,
                'Diagnostic-Code': 'Delivered',
                'Status': '2.0.0',
                'Arrival-Date': 'Fri,  5 Aug 2014 23:35:50 +0700 (WIT)'
            })

        self.assertEqual(
            Message.objects.get(pk=message.pk).status, message.SENT)