コード例 #1
0
 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()
コード例 #2
0
 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')
コード例 #3
0
 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")
コード例 #4
0
 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"]
コード例 #5
0
 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']
コード例 #6
0
 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': '*****@*****.**'
     }
コード例 #7
0
ファイル: test_backend.py プロジェクト: CampusJob/postmarker
 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": "*****@*****.**",
     }
コード例 #8
0
 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(),)