示例#1
0
async def test_msgid_header():
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")

    msg = MailMsg(**message.dict())
    msg_object = await msg._message('*****@*****.**')
    assert msg_object['Message-ID'] is not None
示例#2
0
async def test_message_charset():
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")

    msg = MailMsg(**message.dict())
    msg_object = await msg._message('*****@*****.**')
    assert msg_object._charset is not None
    assert msg_object._charset == "utf-8"
示例#3
0
    async def __prepare_message(self, message: MessageSchema, template=None):
        if template is not None:
            if message.body and not message.html:
                message.body = template.render(body=message.body)
                message.subtype = "html"
            elif message.html:
                message.html = template.render(body=message.html)

        msg = MailMsg(**message.dict())
        if self.config.MAIL_FROM_NAME is not None:
            sender = f"{self.config.MAIL_FROM_NAME} <{self.config.MAIL_FROM}>"
        else:
            sender = self.config.MAIL_FROM
        return await msg._message(sender)
示例#4
0
def test_cc():
    msg = MessageSchema(subject="subject",
                        recipients=[],
                        cc=["*****@*****.**"])

    assert len(msg.cc) == 1
    assert msg.cc == ["*****@*****.**"]
示例#5
0
def test_initialize():
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")

    assert message.subject == "test subject"
示例#6
0
def test_empty_subject_header():
    message = MessageSchema(subject="",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")

    assert len(message.subject) == 0
示例#7
0
def test_message_str():
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")

    assert type(message.body) == str
示例#8
0
def test_charset():
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")

    assert message.charset == "utf-8"
示例#9
0
def test_recipients_properly_initialized():
    message = MessageSchema(subject="test subject",
                            recipients=[],
                            body="test",
                            subtype="plain")

    assert message.recipients == []
示例#10
0
def test_replyto():
    msg = MessageSchema(subject="subject",
                        recipients=[],
                        reply_to=["*****@*****.**"])

    assert len(msg.reply_to) == 1
    assert msg.reply_to == ["*****@*****.**"]
示例#11
0
def test_sendto_properly_set():
    msg = MessageSchema(subject="subject",
                        recipients=["*****@*****.**", "*****@*****.**"],
                        cc=["*****@*****.**"],
                        bcc=["*****@*****.**"])

    assert len(msg.recipients) == 2
    assert len(msg.cc) == 1
    assert len(msg.bcc) == 1
示例#12
0
def test_plain_message_with_attachments():
    directory = os.getcwd()
    attachement = directory + "/files/attachement.txt"

    msg = MessageSchema(subject="testing",
                        recipients=["*****@*****.**"],
                        attachments=[attachement],
                        body="test mail body")

    with open(attachement, "w") as file:
        file.write(CONTENT)

    assert len(msg.attachments) == 1
示例#13
0
def test_multipart_subtype():
    message = MessageSchema(subject="test subject",
                            recipients=["*****@*****.**"],
                            body="test",
                            subtype="plain")
    assert message.multipart_subtype == MultipartSubtypeEnum.mixed