Skip to content

Commit

Permalink
Merge pull request #25 from jproffitt/issue-24
Browse files Browse the repository at this point in the history
fixes issue #24. Correctly send text notification
  • Loading branch information
raiderrobert authored Jan 6, 2017
2 parents e748522 + 2f829a9 commit d9cac4b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:

install:
- travis_retry pip install $DJANGO
- travis_retry pip install coveralls six pytz mock
- travis_retry pip install coveralls six pytz mock twilio

script:
- coverage run --source herald runtests.py -v 2
Expand Down
13 changes: 11 additions & 2 deletions herald/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,17 @@ def send(self, raise_exception=False):
context = self.get_context_data()

recipients = self.get_recipients()
text_content = self.render('text', context)
html_content = self.render('html', context)

if 'text' in self.render_types:
text_content = self.render('text', context)
else:
text_content = None

if 'html' in self.render_types:
html_content = self.render('html', context)
else:
html_content = None

sent_from = self.get_sent_from()
subject = self.get_subject()
extra_data = self.get_extra_data()
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
django>=1.8
six
mock
mock
twilio
23 changes: 21 additions & 2 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core import mail
from django.test import TestCase, override_settings
from mock import patch
from twilio.rest.resources import Messages

from herald.base import NotificationBase, EmailNotification, TwilioTextNotification
from herald.models import SentNotification
Expand Down Expand Up @@ -150,17 +151,35 @@ class TestNotification(TwilioTextNotification):

def test_get_sent_from_default(self):
class TestNotification(TwilioTextNotification):
from_email = None
from_number = None

with override_settings(TWILIO_DEFAULT_FROM_NUMBER='1231231234'):
self.assertEqual(TestNotification().get_sent_from(), '1231231234')

def test_get_sent_from_default_error(self):
class TestNotification(TwilioTextNotification):
from_email = None
from_number = None

self.assertRaisesMessage(
Exception,
'TWILIO_DEFAULT_FROM_NUMBER setting is required for sending a TwilioTextNotification',
TestNotification().get_sent_from
)

@override_settings(
TWILIO_ACCOUNT_SID='sid',
TWILIO_AUTH_TOKEN='token'
)
def test_send(self):
class TestNotification(TwilioTextNotification):
from_number = '1231231234'
to_number = '1231231234'
template_name = 'hello_world'

with patch.object(Messages, 'create') as mocked_create:
TestNotification().send()
mocked_create.assert_called_once_with(
body='Hello World',
to='1231231234',
from_='1231231234'
)

0 comments on commit d9cac4b

Please sign in to comment.