예제 #1
0
파일: tests.py 프로젝트: toxinu/munch-core
 def test_abuse_url(self):
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     self.assertEqual(
         mail.abuse_url,
         'http://test.munch.example.com/abuse/report/{}/'.format(
             mail.identifier))
예제 #2
0
파일: tests.py 프로젝트: toxinu/munch-core
 def test_form_validation(self):
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     f = AbuseNotificationForm({
         'mail': mail.identifier,
         'comments': ''})
     self.assertFalse(f.is_valid())
예제 #3
0
파일: tests.py 프로젝트: toxinu/munch-core
 def test_mail_resolution(self):
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     f = AbuseNotificationForm({
         'mail': mail.identifier,
         'comments': 'test'})
     f.is_valid()
     f.save()
예제 #4
0
파일: tests.py 프로젝트: toxinu/munch-core
    def test_cannot_delete_non_empty_category(self):
        category = CategoryFactory(author=self.user)

        MessageFactory(category=category, author=self.user)

        self.assertEqual(Category.objects.count(), 1)
        self.assertEqual(Category.objects.first().messages.count(), 1)
        resp = self.client.delete('/{}/categories/{}/'.format(
            self.api_prefix, category.pk))
        self.assertEqual(resp.status_code, 403)
        self.assertEqual(Category.objects.count(), 1)
        self.assertEqual(Category.objects.first().messages.count(), 1)
예제 #5
0
 def setUp(self):
     self.user = UserFactory()
     self.message = MessageFactory(
         author=self.user,
         track_clicks=True,
         track_open=False,
         msg_links={'AAAAABBBBB': 'http://example.com'},
         html='<body><a href="http://example.com">Hi</a>{}</body>'.format(
             settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER']))
     with patch('munch.apps.spamcheck.SpamChecker.check',
                side_effect=get_spam_result_mock):
         self.message.save()
예제 #6
0
파일: tests.py 프로젝트: toxinu/munch-core
 def test_abuse_makes_optout(self):
     """ An abuse should create an optout for the given mail """
     user = UserFactory()
     message = MessageFactory(author=user)
     mail = MailFactory(message=message)
     response = self.client.post(
         'http://test.munch.example.com/abuse/report/{}/'.format(
             mail.identifier),
         {'mail': mail.identifier, 'comments': 'test'})
     self.assertEqual(response.status_code, 302)
     optout = OptOut.objects.get(identifier=mail.identifier)
     self.assertEqual(optout.origin, OptOut.BY_ABUSE)
예제 #7
0
    def test_reaction_time(self):
        with fake_time('2016-10-10 08:00:00'):
            message = MessageFactory(status='message_ok', author=self.user)
            mail = MailFactory(message=message)
            MailStatusFactory(mail=mail)
            MailStatusFactory(mail=mail, status=MailStatus.SENDING)
            MailStatusFactory(mail=mail, status=MailStatus.DELIVERED)
        with fake_time('2016-10-10 08:00:15'):
            self.client.get('/t/open/{}'.format(mail.identifier))
            records = TrackRecord.objects.filter(identifier=mail.identifier,
                                                 kind='read')

        self.assertEqual(records.first().properties['reaction_time'], '15')
예제 #8
0
    def test_html_non_generation(self):
        message = MessageFactory(
            author=self.user,
            track_open=False,
            html='<body><h1>Foo</h1>{}</body>'.format(
                settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER']))
        with patch('munch.apps.spamcheck.SpamChecker.check',
                   side_effect=get_spam_result_mock):
            message.save()

        mail = MailFactory(message=message)
        content = message.to_mail(mail)
        self.assertNotIn('pixel.gif', content.alternatives[0][0])
예제 #9
0
    def test_valid_unsubscribe(self):
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)

        recipient = 'unsubscribe-{}@test.munch.example.com'.format(
            mail.identifier)
        unsubscribe = UNSUBSCRIBE_EMAIL.replace('||TO||', recipient)
        unsubscribe = unsubscribe.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(unsubscribe)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = UnsubscribeHandler(envelope, message)
        self.assertIsNotNone(handler.apply())
예제 #10
0
    def test_valid_arf(self):
        user = UserFactory()
        message = MessageFactory(author=user)
        mail = MailFactory(message=message)

        recipient = 'return-{}@test.munch.example.com'.format(
            mail.identifier)
        arf = ARF_REPORT.replace('||TO||', '*****@*****.**')
        arf = arf.replace('||RETURNPATH||', recipient)
        message = email.message_from_string(arf)
        envelope = Envelope()
        envelope.parse_msg(message)
        envelope.recipients = [recipient]
        handler = ARFHandler(envelope, message)
        self.assertIsNotNone(handler.apply())
예제 #11
0
    def test_valid_tracker(self):
        with fake_time('2016-10-10 08:00:00'):
            message = MessageFactory(status='message_ok', author=self.user)
            mail = MailFactory(message=message)
            MailStatusFactory(mail=mail)
            MailStatusFactory(mail=mail, status=MailStatus.SENDING)
            MailStatusFactory(mail=mail, status=MailStatus.DELIVERED)
        with fake_time('2016-10-10 08:00:15'):
            resp = self.client.get('/t/open/{}'.format(mail.identifier))

        self.assertEqual(resp.status_code, 200)
        self.assertEqual(resp['Content-Type'], 'image/gif')
        self.assertEqual(resp.content, TRACKER_PIXEL)

        records = TrackRecord.objects.filter(identifier=mail.identifier,
                                             kind='read',
                                             properties__source=READ_MUA_PIXEL)

        self.assertEqual(records.count(), 1)
예제 #12
0
    def test_html_generation_preserve_doctype(self):
        message = MessageFactory(
            author=self.user,
            track_open=True,
            html=(
                '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E'
                'N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                '<html xmlns="http://www.w3.org/1999/xhtml">{}</html>').format(
                    settings.OPTOUTS['UNSUBSCRIBE_PLACEHOLDER']))

        with patch('munch.apps.spamcheck.SpamChecker.check',
                   side_effect=get_spam_result_mock):
            message.save()

        mail = MailFactory(message=message)
        content = message.to_mail(mail)
        self.assertIn(
            '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
            '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
            content.alternatives[0][0])
예제 #13
0
파일: tests.py 프로젝트: toxinu/munch-core
 def setUp(self):
     self.user = UserFactory()
     self.message = MessageFactory(author=self.user)
예제 #14
0
 def test_invalid_method(self):
     message = MessageFactory(status='message_ok', author=self.user)
     resp = self.client.post('/t/open/{}'.format(message.identifier))
     self.assertEqual(resp.status_code, 405)
예제 #15
0
 def _mk_message(self, sender):
     return MessageFactory(sender_email=sender, author=self.user_1)