mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: add header_data into emails (#20903)
* test sparkpost * added logging info * header function implementation * added test * daniel revisions * daniel revision * elizabeth review
This commit is contained in:
@@ -58,6 +58,37 @@ class TestEmailSmtp(SupersetTestCase):
|
||||
mimeapp = MIMEApplication("attachment")
|
||||
assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
|
||||
|
||||
@mock.patch("superset.utils.core.send_mime_email")
|
||||
def test_send_smtp_with_email_mutator(self, mock_send_mime):
|
||||
attachment = tempfile.NamedTemporaryFile()
|
||||
attachment.write(b"attachment")
|
||||
attachment.seek(0)
|
||||
|
||||
# putting this into a variable so that we can reset after the test
|
||||
base_email_mutator = app.config["EMAIL_HEADER_MUTATOR"]
|
||||
|
||||
def mutator(msg, **kwargs):
|
||||
msg["foo"] = "bar"
|
||||
return msg
|
||||
|
||||
app.config["EMAIL_HEADER_MUTATOR"] = mutator
|
||||
utils.send_email_smtp(
|
||||
"to", "subject", "content", app.config, files=[attachment.name]
|
||||
)
|
||||
assert mock_send_mime.called
|
||||
call_args = mock_send_mime.call_args[0]
|
||||
logger.debug(call_args)
|
||||
assert call_args[0] == app.config["SMTP_MAIL_FROM"]
|
||||
assert call_args[1] == ["to"]
|
||||
msg = call_args[2]
|
||||
assert msg["Subject"] == "subject"
|
||||
assert msg["From"] == app.config["SMTP_MAIL_FROM"]
|
||||
assert msg["foo"] == "bar"
|
||||
assert len(msg.get_payload()) == 2
|
||||
mimeapp = MIMEApplication("attachment")
|
||||
assert msg.get_payload()[-1].get_payload() == mimeapp.get_payload()
|
||||
app.config["EMAIL_HEADER_MUTATOR"] = base_email_mutator
|
||||
|
||||
@mock.patch("superset.utils.core.send_mime_email")
|
||||
def test_send_smtp_data(self, mock_send_mime):
|
||||
utils.send_email_smtp(
|
||||
|
||||
Reference in New Issue
Block a user