Skip to content

Commit

Permalink
Fix settings and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarkentin committed May 2, 2016
1 parent 686f6f6 commit 6ba3593
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions tests/test_views.py
Expand Up @@ -268,9 +268,6 @@ def test_response_version_header(self):
self.assertTrue(response.has_header('X-Watchman-Version'))


# TODO: Figure out why settings defaults aren't working - related to https://github.com/mwarkentin/django-watchman/issues/13?
@override_settings(WATCHMAN_EMAIL_RECIPIENTS=['to@example.com'])
@override_settings(WATCHMAN_EMAIL_HEADERS={})
class TestEmailCheck(DjangoTestCase):
def setUp(self):
# Ensure that every test executes with separate settings
Expand All @@ -288,6 +285,9 @@ def def_test_email_with_default_recipient(self):

@override_settings(WATCHMAN_EMAIL_RECIPIENTS=['custom@example.com'])
def def_test_email_with_custom_recipient(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.
Expand All @@ -299,6 +299,9 @@ def def_test_email_with_custom_recipient(self):

@override_settings(WATCHMAN_EMAIL_RECIPIENTS=['to1@example.com', 'to2@example.com'])
def def_test_email_with_multiple_recipients(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.
Expand All @@ -322,6 +325,9 @@ def test_email_check_with_default_headers(self):

@override_settings(WATCHMAN_EMAIL_HEADERS={'foo': 'bar'})
def test_email_check_with_custom_headers(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.
Expand Down
5 changes: 3 additions & 2 deletions watchman/checks.py
Expand Up @@ -10,6 +10,7 @@
from django.db import connections

from watchman.decorators import check
from watchman import settings as watchman_settings
from watchman import utils


Expand Down Expand Up @@ -43,12 +44,12 @@ def _check_database(database):
@check
def _check_email():
headers = {"X-DJANGO-WATCHMAN": True}
headers.update(settings.WATCHMAN_EMAIL_HEADERS)
headers.update(watchman_settings.WATCHMAN_EMAIL_HEADERS)
email = EmailMessage(
"django-watchman email check",
"This is an automated test of the email system.",
"watchman@example.com",
settings.WATCHMAN_EMAIL_RECIPIENTS,
watchman_settings.WATCHMAN_EMAIL_RECIPIENTS,
headers=headers,
)
email.send()
Expand Down

0 comments on commit 6ba3593

Please sign in to comment.