Skip to content

Commit

Permalink
Make sure that there is a to address in the message
Browse files Browse the repository at this point in the history
The first one in the list of recipients is the to address. The rest
of recipients are sent as Bcc
  • Loading branch information
andresfib committed Jun 15, 2020
1 parent d9fb07e commit 1de4170
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion diffengine/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def mailer(self, api_token):

def build_recipients(self, recipients):
if recipients:
return [Bcc(x.strip()) for x in recipients.split(",")]
return [x.strip() for x in recipients.split(",")]

def build_subject(self, diff):
return diff.old.title
Expand Down
22 changes: 21 additions & 1 deletion test_diffengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def test_do_mail_if_entry_has_diff(self):
sendgrid_config = {
"api_token": "12345",
"sender": "[email protected]",
"recipients": "[email protected], [email protected]",
"recipients": "[email protected]",
}
result = process_entry(entry, {"sendgrid": sendgrid_config}, None, sendgrid)

Expand Down Expand Up @@ -639,6 +639,26 @@ def test_raises_if_not_all_archive_urls_are_present(self):
"sendgrid.publish_diff raised AchiveUrlNotFoundError unexpectedly!"
)

def test_only_one_recipient(self):
config = {
"sendgrid": {
"api_token": "12345",
"sender": "[email protected]",
"recipients": "[email protected]",
}
}

sendgrid = SendgridHandler(config["sendgrid"])

diff = get_mocked_diff(False)
type(diff.old).archive_url = PropertyMock(return_value="http://test.url/old")
type(diff.new).archive_url = PropertyMock(return_value="http://test.url/new")

try:
sendgrid.publish_diff(diff, config["sendgrid"])
except Exception as e:
self.fail(e)


def get_mocked_diff(with_archive_urls=True):
old = MagicMock()
Expand Down

0 comments on commit 1de4170

Please sign in to comment.