Skip to content

Commit

Permalink
Merge pull request #100 from eduardocardoso/96-custom-sender
Browse files Browse the repository at this point in the history
Customize sender for email check
  • Loading branch information
mwarkentin authored Feb 22, 2017
2 parents 15857bb + f4e177d commit 0308af7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ once per minute, this would cost you ~$5.60/month.

**Custom Settings**

* ``WATCHMAN_EMAIL_SENDER`` (default: ``[email protected]``): Specify an email to be the sender of the test email
* ``WATCHMAN_EMAIL_RECIPIENTS`` (default: ``[[email protected]]``): Specify a list of email addresses to send the test email
* ``WATCHMAN_EMAIL_HEADERS`` (default: ``{}``): Specify a dict of custom headers to be added to the test email

Expand Down
24 changes: 24 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,27 @@ def test_email_check_with_custom_headers(self):
'foo': 'bar',
}
self.assertEqual(sent_email.extra_headers, expected_headers)

def def_test_email_with_default_sender(self):
checks._check_email()

# Test that one message has been sent.
self.assertEqual(len(mail.outbox), 1)

sent_email = mail.outbox[0]
expected_sender = '[email protected]'
self.assertEqual(sent_email.from_email, expected_sender)

@override_settings(WATCHMAN_EMAIL_SENDER='[email protected]')
def def_test_email_with_custom_sender(self):
# Have to manually reload settings here because override_settings
# happens after self.setUp()
reload_settings()
checks._check_email()

# Test that one message has been sent.
self.assertEqual(len(mail.outbox), 1)

sent_email = mail.outbox[0]
expected_sender = '[email protected]'
self.assertEqual(sent_email.from_email, expected_sender)
2 changes: 1 addition & 1 deletion watchman/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _check_email():
email = EmailMessage(
"django-watchman email check",
"This is an automated test of the email system.",
"[email protected]",
watchman_settings.WATCHMAN_EMAIL_SENDER,
watchman_settings.WATCHMAN_EMAIL_RECIPIENTS,
headers=headers,
)
Expand Down
1 change: 1 addition & 0 deletions watchman/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
WATCHMAN_TOKENS = getattr(settings, 'WATCHMAN_TOKENS', None)
WATCHMAN_TOKEN_NAME = getattr(settings, 'WATCHMAN_TOKEN_NAME', 'watchman-token')
WATCHMAN_ERROR_CODE = getattr(settings, 'WATCHMAN_ERROR_CODE', 500)
WATCHMAN_EMAIL_SENDER = getattr(settings, 'WATCHMAN_EMAIL_SENDER', '[email protected]')
WATCHMAN_EMAIL_RECIPIENTS = getattr(settings, 'WATCHMAN_EMAIL_RECIPIENTS', ['[email protected]'])
WATCHMAN_EMAIL_HEADERS = getattr(settings, 'WATCHMAN_EMAIL_HEADERS', {})

Expand Down

0 comments on commit 0308af7

Please sign in to comment.