def _construct_email(self, email, **extra): """Converts incoming data to properly structured dictionary.""" if isinstance(email, dict): email = Email(manager=self._manager, **email) elif not isinstance(email, EmailTemplate): print(type(email)) raise ValueError email._update(extra) return email.as_dict()
def test_body(self): with pytest.raises(AssertionError) as exc: Email(From='*****@*****.**', To='*****@*****.**', Subject='Postmark test') assert str(exc.value).startswith( 'Provide either email TextBody or HtmlBody or both')
def test_body(self): with pytest.raises(AssertionError) as exc: Email( From="*****@*****.**", To="*****@*****.**", Subject="Postmark test", ) assert str(exc.value).startswith("Provide either email TextBody or HtmlBody or both")
def test_from_mime(self, postmark): email = Email.from_mime(MIME_MESSAGE, postmark) assert email.TextBody == "Text" assert email.From == MIME_MESSAGE["From"] assert email.To == MIME_MESSAGE["To"] assert email.Subject == MIME_MESSAGE["Subject"] assert email.Cc == MIME_MESSAGE["Cc"] assert email.Bcc == MIME_MESSAGE["Bcc"] assert email.ReplyTo == MIME_MESSAGE["Reply-To"]
def test_from_mime(self, postmark): email = Email.from_mime(MIME_MESSAGE, postmark) assert email.TextBody == 'Text' assert email.From == MIME_MESSAGE['From'] assert email.To == MIME_MESSAGE['To'] assert email.Subject == MIME_MESSAGE['Subject'] assert email.Cc == MIME_MESSAGE['Cc'] assert email.Bcc == MIME_MESSAGE['Bcc'] assert email.ReplyTo == MIME_MESSAGE['Reply-To']
def test_pre_send(self, catch_signal): with catch_signal(pre_send) as handler: send_mail(**SEND_KWARGS) assert handler.called kwargs = handler.call_args[1] assert kwargs['sender'] == EmailBackend assert kwargs['signal'] == pre_send assert len(kwargs['messages']) == 1 message = kwargs['messages'][0] assert Email.from_mime(message, None).as_dict() == { 'Attachments': [], 'Bcc': None, 'Cc': None, 'From': '*****@*****.**', 'Headers': [], 'HtmlBody': None, 'ReplyTo': None, 'Subject': 'Subject here', 'Tag': None, 'TextBody': 'Here is the message.', 'To': '*****@*****.**' }
def test_pre_send(self, catch_signal): with catch_signal(pre_send) as handler: send_mail(**SEND_KWARGS) assert handler.called kwargs = handler.call_args[1] assert kwargs["sender"] == EmailBackend assert kwargs["signal"] == pre_send assert len(kwargs["messages"]) == 1 message = kwargs["messages"][0] assert Email.from_mime(message, None).as_dict() == { "Attachments": [], "Bcc": None, "Cc": None, "From": "*****@*****.**", "Headers": [], "HtmlBody": None, "ReplyTo": None, "Subject": "Subject here", "Tag": None, "TextBody": "Here is the message.", "To": "*****@*****.**", }
def test_mime(self, postmark, postmark_request): postmark.emails.send_batch(MIME_MESSAGE) email = Email.from_mime(MIME_MESSAGE, postmark) assert postmark_request.call_args[1]["json"] == (email.as_dict(),)