Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/user_preferences
Browse files Browse the repository at this point in the history
# Conflicts:
#	herald/base.py
#	requirements.txt
  • Loading branch information
georgmzimmer committed Apr 7, 2017
2 parents f3a4b71 + 29356c9 commit 2e30ed0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ python:

env:
- DJANGO='https://github.com/django/django/archive/master.tar.gz'
- DJANGO='django==1.11rc1'
- DJANGO='django>=1.11.0,<1.12.0'
- DJANGO='django>=1.10.0,<1.11.0'
- DJANGO='django>=1.9.0,<1.10.0'
- DJANGO='django>=1.8.0,<1.9.0'

install:
- travis_retry pip install --upgrade pip setuptools wheel
- travis_retry pip install --upgrade $DJANGO
- travis_retry pip install --upgrade coveralls six pytz mock twilio
- travis_retry pip install --upgrade -r requirements.txt

script:
- coverage run --source herald runtests.py -v 2
Expand All @@ -35,7 +36,7 @@ matrix:
- python: "3.3"
env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
- python: "3.3"
env: DJANGO='django==1.11rc1'
env: DJANGO='django>=1.11.0,<1.12.0'
- python: "3.3"
env: DJANGO='django>=1.10.0,<1.11.0'
- python: "3.3"
Expand Down
33 changes: 14 additions & 19 deletions herald/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,15 @@ def get_sent_from(self):

@staticmethod
def _send(recipients, text_content=None, html_content=None, sent_from=None, subject=None, extra_data=None):
client = TwilioTextNotification.setup_client()

num_of_messages = 0

for recipient in recipients:
client.messages.create(
body=text_content,
to=recipient,
from_=sent_from
)
num_of_messages += 1

return num_of_messages

@staticmethod
def setup_client():
try:
import twilio
# twilio version 6
from twilio.rest import Client
except ImportError:
raise Exception('Twilio is required for sending a TwilioTextNotification.')
try:
# twillio version < 6
from twilio.rest import TwilioRestClient as Client
except ImportError:
raise Exception('Twilio is required for sending a TwilioTextNotification.')

try:
account_sid = settings.TWILIO_ACCOUNT_SID
Expand All @@ -315,4 +304,10 @@ def setup_client():
'TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN settings are required for sending a TwilioTextNotification'
)

return twilio.rest.TwilioRestClient(account_sid, auth_token)
client = Client(account_sid, auth_token)

client.messages.create(
body=text_content,
to=recipients[0],
from_=sent_from
)
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
django>=1.8
six
mock
twilio==5.7.0
twilio
coveralls
pytz
10 changes: 8 additions & 2 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from django.core import mail
from django.test import TestCase, override_settings
from mock import patch
from twilio.rest.resources import Messages

try:
# twilio version 6
from twilio.rest.api.v2010.account import MessageList
except ImportError:
# twillio version < 6
from twilio.rest.resources import Messages as MessageList

from herald.base import NotificationBase, EmailNotification, TwilioTextNotification
from herald.models import SentNotification
Expand Down Expand Up @@ -176,7 +182,7 @@ class TestNotification(TwilioTextNotification):
to_number = '1231231234'
template_name = 'hello_world'

with patch.object(Messages, 'create') as mocked_create:
with patch.object(MessageList, 'create') as mocked_create:
TestNotification().send()
mocked_create.assert_called_once_with(
body='Hello World',
Expand Down

0 comments on commit 2e30ed0

Please sign in to comment.