Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Bump twilio library to v6.0.0rc12
Browse files Browse the repository at this point in the history
  • Loading branch information
mcelicalderon committed Sep 29, 2016
1 parent a017cdc commit 57a0147
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
File renamed without changes.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<a href="https://www.twilio.com">
<img src="https://static0.twilio.com/marketing/bundles/marketing/img/logos/wordmark-red.svg" alt="Twilio" width="250" />
</a>

# Call Tracking (Django)

[![Build Status](https://travis-ci.org/TwilioDevEd/call-tracking-django.svg?branch=master)](https://travis-ci.org/TwilioDevEd/call-tracking-django)
Expand Down Expand Up @@ -98,3 +102,9 @@ $ coverage run manage.py test --settings=twilio_sample_project.settings.test
```

You can then view the results with `coverage report` or build an HTML report with `coverage html`.

## Meta

* No warranty expressed or implied. Software is as is. Diggity.
* [MIT License](http://www.opensource.org/licenses/mit-license.html)
* Lovingly crafted by Twilio Developer Education.
10 changes: 5 additions & 5 deletions call_tracking/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ class SearchPhoneNumbersTest(TestCase):

def test_search_phone_numbers(self):
# Act
with patch('twilio.rest.resources.phone_numbers.AvailablePhoneNumbers.list') as mock:
with patch('twilio.rest.api.v2010.account.available_phone_number.local.LocalList.list') as mock:
search_phone_numbers()

# Assert
self.assertTrue(mock.called)
mock.assert_called_with(area_code=None, country='US')
mock.assert_called_with(area_code=None)

def test_search_phone_numbers_with_area_code(self):
# Act
with patch('twilio.rest.resources.phone_numbers.AvailablePhoneNumbers.list') as mock:
with patch('twilio.rest.api.v2010.account.available_phone_number.local.LocalList.list') as mock:
search_phone_numbers(415)

# Assert
self.assertTrue(mock.called)
mock.assert_called_with(area_code=415, country='US')
mock.assert_called_with(area_code=415)


class PurchasePhoneNumberTest(TestCase):

def test_purchase_phone_number(self):
# Act
with patch('twilio.rest.resources.phone_numbers.PhoneNumbers.purchase') as mock:
with patch('twilio.rest.api.v2010.account.incoming_phone_number.IncomingPhoneNumberList.create') as mock:
purchase_phone_number(phone_number='+15555555555')

# Assert
Expand Down
13 changes: 9 additions & 4 deletions call_tracking/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
from django.conf import settings
from twilio.rest import TwilioRestClient
from twilio.rest import Client

import os

# Uses credentials defined in TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN
# environment variables
client = TwilioRestClient()
account_sid = settings.TWILIO_ACCOUNT_SID
auth_token = settings.TWILIO_AUTH_TOKEN

client = Client(account_sid, auth_token)


def search_phone_numbers(area_code=None):
"""Queries the Twilio REST API to get phone numbers available for puchase"""
# You can change the country argument to search outside the US
# area_code is an optional parameter
numbers = client.phone_numbers.search(area_code=area_code, country='US')
numbers = client.available_phone_numbers("US") \
.local \
.list(area_code=area_code)

# Returns 30 by default - let's trim the list for UX purposes
return numbers[:10]
Expand All @@ -21,7 +26,7 @@ def search_phone_numbers(area_code=None):
def purchase_phone_number(phone_number):
"""Purchases a new phone number from the Twilio API"""
# Use a TwiML Application SID so all our numbers use the same voice URL
number = client.phone_numbers.purchase(
number = client.incoming_phone_numbers.create(
phone_number=phone_number,
voice_application_sid=settings.TWIML_APPLICATION_SID)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ django-forms-bootstrap==3.0.1
django-phonenumber-field==0.7.2
phonenumbers==7.0.8
psycopg2==2.6.1
twilio==4.4.0
twilio==6.0.0rc12
whitenoise==2.0.2

# Production dependencies
Expand Down
16 changes: 16 additions & 0 deletions twilio_sample_project/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@
"""
raise ImproperlyConfigured(missing_application_sid_message)

TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID', None)
if not TWILIO_ACCOUNT_SID:
missing_account_sid_message = \
"""
You *must* set a TWILIO_ACCOUNT_SID environment variable to run this app.
"""
raise ImproperlyConfigured(missing_account_sid_message)

TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN', None)
if not TWILIO_AUTH_TOKEN:
missing_auth_token_message = \
"""
You *must* set a TWILIO_AUTH_TOKEN environment variable to run this app.
"""
raise ImproperlyConfigured(missing_auth_token_message)

# Application definition

DJANGO_APPS = (
Expand Down

0 comments on commit 57a0147

Please sign in to comment.