From d7c36f4edaa0142b6131c386f9daf0aa3e4f6559 Mon Sep 17 00:00:00 2001 From: Eduardo Cardoso Date: Tue, 21 Feb 2017 15:03:45 -0300 Subject: [PATCH 1/3] #96: Get email sender from settings --- watchman/checks.py | 2 +- watchman/settings.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/watchman/checks.py b/watchman/checks.py index 804d6d1..2eff749 100644 --- a/watchman/checks.py +++ b/watchman/checks.py @@ -48,7 +48,7 @@ def _check_email(): email = EmailMessage( "django-watchman email check", "This is an automated test of the email system.", - "watchman@example.com", + watchman_settings.WATCHMAN_EMAIL_SENDER, watchman_settings.WATCHMAN_EMAIL_RECIPIENTS, headers=headers, ) diff --git a/watchman/settings.py b/watchman/settings.py index 874071d..5e884d6 100644 --- a/watchman/settings.py +++ b/watchman/settings.py @@ -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', 'watchman@example.com') WATCHMAN_EMAIL_RECIPIENTS = getattr(settings, 'WATCHMAN_EMAIL_RECIPIENTS', ['to@example.com']) WATCHMAN_EMAIL_HEADERS = getattr(settings, 'WATCHMAN_EMAIL_HEADERS', {}) From cf7598983ab7e4f6c22cb9f0937d9ce04ad66ab6 Mon Sep 17 00:00:00 2001 From: Eduardo Cardoso Date: Tue, 21 Feb 2017 15:03:59 -0300 Subject: [PATCH 2/3] #96: Add tests for custom and default email sender --- tests/test_views.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_views.py b/tests/test_views.py index 2df8fc2..a48ef82 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -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 = 'watchman@example.com' + self.assertEqual(sent_email.from_email, expected_sender) + + @override_settings(WATCHMAN_EMAIL_SENDER='custom@example.com') + 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 = 'custom@example.com' + self.assertEqual(sent_email.from_email, expected_sender) From f4e177d5d17b51ca5ec774879e26ea8bf2c9d1a4 Mon Sep 17 00:00:00 2001 From: Eduardo Cardoso Date: Tue, 21 Feb 2017 15:04:05 -0300 Subject: [PATCH 3/3] #96: Add email sender setting to README --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 62b1512..8c7a1d9 100644 --- a/README.rst +++ b/README.rst @@ -233,6 +233,7 @@ once per minute, this would cost you ~$5.60/month. **Custom Settings** +* ``WATCHMAN_EMAIL_SENDER`` (default: ``watchman@example.com``): Specify an email to be the sender of the test email * ``WATCHMAN_EMAIL_RECIPIENTS`` (default: ``[to@example.com]``): 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