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
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"
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)
def test_cc(): msg = MessageSchema(subject="subject", recipients=[], cc=["*****@*****.**"]) assert len(msg.cc) == 1 assert msg.cc == ["*****@*****.**"]
def test_initialize(): message = MessageSchema(subject="test subject", recipients=["*****@*****.**"], body="test", subtype="plain") assert message.subject == "test subject"
def test_empty_subject_header(): message = MessageSchema(subject="", recipients=["*****@*****.**"], body="test", subtype="plain") assert len(message.subject) == 0
def test_message_str(): message = MessageSchema(subject="test subject", recipients=["*****@*****.**"], body="test", subtype="plain") assert type(message.body) == str
def test_charset(): message = MessageSchema(subject="test subject", recipients=["*****@*****.**"], body="test", subtype="plain") assert message.charset == "utf-8"
def test_recipients_properly_initialized(): message = MessageSchema(subject="test subject", recipients=[], body="test", subtype="plain") assert message.recipients == []
def test_replyto(): msg = MessageSchema(subject="subject", recipients=[], reply_to=["*****@*****.**"]) assert len(msg.reply_to) == 1 assert msg.reply_to == ["*****@*****.**"]
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
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
def test_multipart_subtype(): message = MessageSchema(subject="test subject", recipients=["*****@*****.**"], body="test", subtype="plain") assert message.multipart_subtype == MultipartSubtypeEnum.mixed