def test_plain_text_with_attachments():
    msg = Message(from_address="*****@*****.**",
                  to="*****@*****.**",
                  subject="hello",
                  body="hello world")
    msg.attach_attachment(content_type="text/plain", data=b"this is test")
    assert "Content-Type: multipart/mixed" in str(msg)
def test_attachment_unicode_filename():
    msg = Message(from_address="*****@*****.**", to="*****@*****.**")
    # Chinese filename :)
    msg.attach_attachment("我的测试文档.txt", "text/plain", "this is test")
    assert "UTF8''%E6%88%91%E7%9A%84%E6%B5%8B%E8%AF" "%95%E6%96%87%E6%A1%A3.txt" in str(
        msg)
def test_attachment_ascii_filename():
    msg = Message(from_address="*****@*****.**", to="*****@*****.**")
    msg.attach_attachment("my test doc.txt", "text/plain", b"this is test")
    assert "Content-Disposition: attachment; filename=" '"my test doc.txt"' in str(
        msg)
def test_attach_attachment():
    msg = Message()
    msg.attach_attachment("test.txt", "text/plain", "this is test")
    assert msg.attachments[0].filename == "test.txt"
    assert msg.attachments[0].content_type == "text/plain"
    assert msg.attachments[0].data == "this is test"