예제 #1
0
    def test_message_with_smart_spoofing_setting_and_not_allowed(self):
        """Testing EmailMessage.message with
        settings.EMAIL_ENABLE_SMART_SPOOFING=True and
        From address not allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=quarantine;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(
            email.extra_headers['From'],
            'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(
            msg['From'], 'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'], 'Doc Dwarf <*****@*****.**>')
예제 #2
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_enable_smart_spoofing_false(self):
        """Testing EmailMessage.message with enable_smart_spoofing=False"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=False)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], 'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
예제 #3
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_from_spoofing_setting_smart_and_not_allowed(self):
        """Testing EmailMessage.message with
        settings.DJBLETS_EMAIL_FROM_SPOOFING=smart and From address not allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=quarantine;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
예제 #4
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_from_spoofing_setting_never(self):
        """Testing EmailMessage.message with
        settings.DJBLETS_EMAIL_FROM_SPOOFING=never
        """
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
예제 #5
0
    def test_message_with_enable_smart_spoofing_false(self):
        """Testing EmailMessage.message with enable_smart_spoofing=False"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=False)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], 'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
예제 #6
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_sender(self):
        """Testing EmailMessage.message with sender="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**',
                             enable_smart_spoofing=False)

        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Sender'], '*****@*****.**')
        self.assertEqual(msg['X-Sender'], '*****@*****.**')
예제 #7
0
    def test_message_with_from_spoofing_setting_never(self):
        """Testing EmailMessage.message with
        settings.DJBLETS_EMAIL_FROM_SPOOFING=never
        """
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
예제 #8
0
    def test_message_with_sender(self):
        """Testing EmailMessage.message with sender="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**',
                             enable_smart_spoofing=False)

        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Sender'], '*****@*****.**')
        self.assertEqual(msg['X-Sender'], '*****@*****.**')
예제 #9
0
    def test_send_with_unicode_subject(self):
        """Testing EmailMessage.send with a Unicode subject"""
        email = EmailMessage(subject='\U0001f604',
                             text_body='This is a test',
                             html_body='<p>This is a test</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
예제 #10
0
파일: tests.py 프로젝트: adhulipa/djblets
    def test_send_email_unicode_subject(self):
        """Testing sending an EmailMessage with a unicode subject"""
        email = EmailMessage(subject='\ud83d\ude04',
                             text_body='This is a test',
                             html_body='<p>This is a test</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
예제 #11
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_prevent_auto_responses_false(self):
        """Testing EmailMessage.message with prevent_auto_responses=False"""
        # prevent_auto_responses is False by default, so test with that case
        # to ensure it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('X-Auto-Response-Suppress', email._headers)

        msg = email.message()
        self.assertNotIn('X-Auto-Response-Suppress', msg)
예제 #12
0
    def test_message_with_prevent_auto_responses_false(self):
        """Testing EmailMessage.message with prevent_auto_responses=False"""
        # prevent_auto_responses is False by default, so test with that case
        # to ensure it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('X-Auto-Response-Suppress', email._headers)

        msg = email.message()
        self.assertNotIn('X-Auto-Response-Suppress', msg)
예제 #13
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_auto_generated_false(self):
        """Testing EmailMessage.message with auto_generated=False"""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('Auto-Submitted', email._headers)

        msg = email.message()
        self.assertNotIn('Auto-Submitted', msg)
예제 #14
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_auto_generated_true(self):
        """Testing EmailMessage.message with auto_generated=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             auto_generated=True)

        self.assertIn('Auto-Submitted', email._headers)
        self.assertEqual(email._headers['Auto-Submitted'], 'auto-generated')

        msg = email.message()
        self.assertEqual(msg['Auto-Submitted'], 'auto-generated')
예제 #15
0
파일: tests.py 프로젝트: adhulipa/djblets
    def test_send_email_unicode_body(self):
        """Testing sending an EmailMessage with a unicode body"""
        email = EmailMessage(subject='Test email',
                             text_body='\ud83d\ude04',
                             html_body='<p>\ud83d\ude04</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        # If the e-mail doesn't send correctly, it will raise a
        # UnicodeDecodeError.
        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
예제 #16
0
    def test_message_with_auto_generated_false(self):
        """Testing EmailMessage.message with auto_generated=False"""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('Auto-Submitted', email._headers)

        msg = email.message()
        self.assertNotIn('Auto-Submitted', msg)
예제 #17
0
    def test_message_with_auto_generated_true(self):
        """Testing EmailMessage.message with auto_generated=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             auto_generated=True)

        self.assertIn('Auto-Submitted', email._headers)
        self.assertEqual(email._headers['Auto-Submitted'], 'auto-generated')

        msg = email.message()
        self.assertEqual(msg['Auto-Submitted'], 'auto-generated')
예제 #18
0
    def test_send_with_unicode_body(self):
        """Testing EmailMessage.send with a Unicode body"""
        email = EmailMessage(subject='Test email',
                             text_body='\U0001f604',
                             html_body='<p>\U0001f604</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        # If the e-mail doesn't send correctly, it will raise a
        # UnicodeDecodeError.
        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
예제 #19
0
    def _create_message(self):
        """Return a new EmailMessage for testing.

        This will contain a sample recipient and initial
        :mailheader:`Message-ID`.

        Returns:
            djblets.mail.message.EmailMessage:
            The resulting message.
        """
        message = EmailMessage(to=['*****@*****.**'])
        message.extra_headers['Message-ID'] = '<*****@*****.**>'

        return message
예제 #20
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_prevent_auto_responses_true(self):
        """Testing EmailMessage.message with prevent_auto_responses=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             prevent_auto_responses=True)

        self.assertIn('X-Auto-Response-Suppress', email._headers)
        self.assertEqual(email._headers['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')

        msg = email.message()
        self.assertEqual(msg['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')
예제 #21
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_extra_headers_dict(self):
        """Testing EmailMessage.message with extra headers as a dict"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers={
                                 'X-Foo': 'Bar',
                             })

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(message['X-Foo'], 'Bar')
예제 #22
0
    def test_message_with_prevent_auto_responses_true(self):
        """Testing EmailMessage.message with prevent_auto_responses=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             prevent_auto_responses=True)

        self.assertIn('X-Auto-Response-Suppress', email._headers)
        self.assertEqual(email._headers['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')

        msg = email.message()
        self.assertEqual(msg['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')
예제 #23
0
    def test_message_with_extra_headers_dict(self):
        """Testing EmailMessage.message with extra headers as a dict"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers={
                                 'X-Foo': 'Bar',
                             })

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(message['X-Foo'], 'Bar')
예제 #24
0
    def test_message_with_in_reply_to(self):
        """Testing EmailMessage.message with in_reply_to="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             in_reply_to='*****@*****.**')

        self.assertIn('In-Reply-To', email._headers)
        self.assertIn('References', email._headers)
        self.assertEqual(email._headers['In-Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['References'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['In-Reply-To'], '*****@*****.**')
        self.assertEqual(msg['References'], '*****@*****.**')
예제 #25
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_in_reply_to(self):
        """Testing EmailMessage.message with in_reply_to="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             in_reply_to='*****@*****.**')

        self.assertIn('In-Reply-To', email._headers)
        self.assertIn('References', email._headers)
        self.assertEqual(email._headers['In-Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['References'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['In-Reply-To'], '*****@*****.**')
        self.assertEqual(msg['References'], '*****@*****.**')
예제 #26
0
    def test_message_with_extra_headers_multivalue_dict(self):
        """Testing EmailMessage.message with extra headers as a MultiValueDict
        """
        header_values = ['Bar', 'Baz']

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers=MultiValueDict({
                                 'X-Foo': header_values,
                             }))

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(set(message.get_all('X-Foo')), set(header_values))
예제 #27
0
파일: tests.py 프로젝트: adhulipa/djblets
    def test_extra_headers_dict(self):
        """Testing sending extra headers as a dict with an e-mail message"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers={
                                 'X-Foo': 'Bar',
                             })

        email.send()

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]

        self.assertIn('X-Foo', message._headers)
        self.assertEqual(message._headers['X-Foo'], 'Bar')
예제 #28
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_extra_headers_multivalue_dict(self):
        """Testing EmailMessage.message with extra headers as a MultiValueDict
        """
        header_values = ['Bar', 'Baz']

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers=MultiValueDict({
                                 'X-Foo': header_values,
                             }))

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(set(message.get_all('X-Foo')),
                         set(header_values))
예제 #29
0
    def test_init_with_text_body_as_bytes(self):
        """Testing EmailMessage.__init__ with text_body=<bytes>"""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body=b'This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertEqual(email.body, 'This is a test.')
        self.assertIsInstance(email.body, six.text_type)
예제 #30
0
    def test_init_with_html_body(self):
        """Testing EmailMessage.__init__ with html_body="""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertEqual(email.alternatives,
                         [('<p>This is a test.</p>', 'text/html')])
예제 #31
0
파일: tests.py 프로젝트: adhulipa/djblets
    def test_extra_headers_multivalue_dict(self):
        """Testing sending extra headers as a MultiValueDict with an e-mail
        message
        """
        header_values = ['Bar', 'Baz']

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers=MultiValueDict({
                                 'X-Foo': header_values,
                             }))

        email.send()

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]

        self.assertIn('X-Foo', message._headers)
        self.assertEqual(set(message._headers.getlist('X-Foo')),
                         set(header_values))
예제 #32
0
파일: tests.py 프로젝트: adhulipa/djblets
    def test_headers_from_sender(self):
        """Testing EmailMessage From/Sender headers"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Sender'], '*****@*****.**')
        self.assertEqual(msg['X-Sender'], '*****@*****.**')
예제 #33
0
파일: tests.py 프로젝트: davidt/djblets
    def test_message_with_from(self):
        """Testing EmailMessage.message with from_email="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email._headers['X-Sender'],
                         settings.DEFAULT_FROM_EMAIL)

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Reply-To'], '*****@*****.**')
예제 #34
0
    def test_message_with_from(self):
        """Testing EmailMessage.message with from_email="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email._headers['X-Sender'],
                         settings.DEFAULT_FROM_EMAIL)

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Reply-To'], '*****@*****.**')
예제 #35
0
    def test_message_with_enable_smart_spoofing_true_and_allowed(self):
        """Testing EmailMessage.message with enable_smart_spoofing=True and
        From address allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=none;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=True)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
예제 #36
0
파일: tests.py 프로젝트: chipx86/djblets
    def test_message_with_enable_smart_spoofing_true_and_allowed(self):
        """Testing EmailMessage.message with enable_smart_spoofing=True and
        From address allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=none;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=True)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')