Skip to content

Commit

Permalink
Made better tests for setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rroskam committed Oct 24, 2016
1 parent 0f4f59d commit efaf4d2
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.core import mail
from django.test import TestCase, override_settings
from mock import patch
from mock import patch, MagicMock

from herald.base import NotificationBase, EmailNotification, TwilioTextNotification
from herald.models import SentNotification
Expand Down Expand Up @@ -178,7 +178,26 @@ def test_setup_client(self):
class TestNotification(TwilioTextNotification):
from_number = '1231231234'

with self.assertRaises(Exception):
TestNotification.setup_client()
self.assertRaisesMessage(
Exception,
'Twilio is required for sending a TwilioTextNotification.',
TestNotification.setup_client
)

with patch.dict('sys.modules', {'twilio': MagicMock()}):

self.assertRaisesMessage(
Exception,
'TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN settings'
' are required for sending a TwilioTextNotification',
TestNotification.setup_client
)

with patch.dict('sys.modules', {'twilio': MagicMock()}), \
override_settings(TWILIO_ACCOUNT_SID='foo', TWILIO_AUTH_TOKEN='bar'):
try:
TestNotification.setup_client()
except Exception:
self.fail('Unexpected failure; maybe there are new settings to override?')


0 comments on commit efaf4d2

Please sign in to comment.