Test Mail.Attachment sending test_tools.py itself
This commit is contained in:
@@ -161,6 +161,21 @@ class TestMail(unittest.TestCase):
|
||||
message='world'))
|
||||
TestMail.DummySMTP.inbox.pop()
|
||||
|
||||
def test_attachment(self):
|
||||
module_file = os.path.abspath(__file__)
|
||||
mail = Mail()
|
||||
mail.settings.server = 'smtp.example.com:25'
|
||||
mail.settings.sender = 'you@example.com'
|
||||
self.assertTrue(mail.send(to=['somebody@example.com'],
|
||||
subject='hello',
|
||||
message='world',
|
||||
attachments=Mail.Attachment(module_file)))
|
||||
message = TestMail.DummySMTP.inbox.pop()
|
||||
import email
|
||||
parsed_msg = email.message_from_string(message.payload)
|
||||
attachment = parsed_msg.get_payload(1).get_payload(decode=True)
|
||||
with open(module_file, 'rb') as mf:
|
||||
self.assertEqual(attachment.decode('utf-8'), mf.read().decode('utf-8'))
|
||||
|
||||
# TODO class TestRecaptcha(unittest.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user