def test_attach(self):
        message = EmailMessage(
            'mail_templated_test/plain.tpl', {'name': 'User'},
            'from@inter.net', ['to@inter.net'])
        # Attach binary file because of strange encoding issue with textual
        # attachments on Django 1.6-1.8 and Python 3.
        file_name = os.path.join(os.path.dirname(__file__), 'test_utils',
                                 'attachment.png')
        message.attach_file(file_name, 'image/png')
        message.send()
        self._assertMessage(
            'from@inter.net', ['to@inter.net'], 'Hello User',
            'User, this is a plain text message.')
        self.assertEqual(len(message.attachments), 1)
        self.assertEqual(message.attachments[0][0], 'attachment.png')
        self.assertTrue(len(message.attachments[0][1]) > 0)
        self.assertEqual(message.attachments[0][2], 'image/png')
dataset/ETHPy150Open artemrizhov/django-mail-templated/mail_templated/tests.py/EmailMessageTestCase.test_attach/original