8000 Merge branch 'master' of https://github.com/twilio/python-private int… · rbarner14/twilio-python@734a571 · GitHub
[go: up one dir, main page]

Skip to content

Commit 734a571

Browse files
committed
Merge branch 'master' of https://github.com/twilio/python-private into sip-trunking
2 parents 13da73b + 15bc4cb commit 734a571

22 files changed

+452
-9
lines changed

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ python:
55
- '3.2'
66
- '3.3'
77
- '3.4'
8+
- '3.5'
89
install:
9-
- pip install . --use-mirrors
10-
- pip install -r requirements.txt --use-mirrors
11-
- pip install -r tests/requirements.txt --use-mirrors
10+
- pip install .
11+
- pip install -r requirements.txt
12+
- pip install -r tests/requirements.txt
1213
script:
1314
- flake8 --ignore=F401 twilio
1415
- flake8 --ignore=E123,E126,E128,E501 tests

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ twilio-python Changelog
33

44
Here you can see the full list of changes between each twilio-python release.
55

6+
Version 4.8.0
7+
-------------
8+
9+
- Add support for SMS pricing
10+
11+
12+
Version 4.6.0
13+
-------------
14+
15+
- Add /Keys endpoint
16+
617
Version 4.6.0
718
-------------
819

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
six
22
httplib2
33
socksipy-branch
4+
pyjwt

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
':python_version=="3.2"': ['pysocks'],
3535
':python_version=="3.3"': ['pysocks'],
3636
':python_version=="3.4"': ['pysocks'],
37+
':python_version=="3.5"': ['pysocks'],
3738
},
3839
packages = find_packages(),
3940
include_package_data=True,
@@ -49,6 +50,7 @@
4950
"Programming Language :: Python :: 3.2",
5051
"Programming Language :: Python :: 3.3",
5152
"Programming Language :: Python :: 3.4",
53+
"Programming Language :: Python :: 3.5",
5254
"Topic :: Software Development :: Libraries :: Python Modules",
5355
"Topic :: Communications :: Telephony",
5456
],
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import unittest
2+
from mock import patch
3+
from nose.tools import assert_equal
4+
from tests.tools import create_mock_json
5+
from twilio.rest.resources.pricing.messaging_countries import (
6+
MessagingCountries
7+
)
8+
9+
AUTH = ("AC123", "token")
10+
BASE_URI = "https://pricing.twilio.com/v1"
11+
12+
13+
class MessagingCountriesTest(unittest.TestCase):
14+
15+
@patch('twilio.rest.resources.base.make_twilio_request')
16+
def test_messaging_countries(self, request):
17+
resp = create_mock_json(
18+
'tests/resources/pricing/messaging_countries_list.json')
19+
resp.status_code = 200
20+
request.return_value = resp
21+
22+
countries = MessagingCountries(BASE_URI + "/Messaging", AUTH)
23+
result = countries.list()
24+
25+
assert_equal(result[0].iso_country, "AT")
26+
assert_equal(len(result), 2)
27+
28+
request.assert_called_with(
29+
"GET",
30+
"{0}/Messaging/Countries".format(BASE_URI),
31+
auth=AUTH,
32+
use_json_extension=False,
33+
params={}
34+
)
35+
36+
@patch('twilio.rest.resources.base.make_twilio_request')
37+
def test_messaging_country(self, request):
38+
resp = create_mock_json(
39+
'tests/resources/pricing/messaging_countries_instance.json')
40+
resp.status_code = 200
41+
request.return_value = resp
42+
43+
countries = MessagingCountries(BASE_URI + "/Messaging", AUTH)
44+
result = countries.get('US')
45+
46+
assert_equal(result.iso_country, "US")
47+
assert_equal(result.price_unit, "usd")
48+
assert_equal(result.outbound_sms_prices[0]['mcc'], "311")
49+
assert_equal(result.outbound_sms_prices[0]['mnc'], "484")
50+
assert_equal(result.outbound_sms_prices[0]['carrier'], "Verizon")
51+
prices = result.outbound_sms_prices[0]['prices']
52+
53+
assert_equal(prices[0]['number_type'], "mobile")
54+
assert_equal(prices[0]['base_price'], "0.0075")
55+
assert_equal(prices[0]['current_price'], "0.0070")
56+
57+
assert_equal(prices[1]['number_type'], "local")
58+
assert_equal(prices[1]['base_price'], "0.0075")
59+
assert_equal(prices[1]['current_price'], "0.0070")
60+
61+
assert_equal(prices[2]['number_type'], "shortcode")
62+
assert_equal(prices[2]['base_price'], "0.01")
63+
assert_equal(prices[2]['current_price'], "0.01")
64+
65+
assert_equal(prices[3]['number_type'], "toll-free")
66+
assert_equal(prices[3]['base_price'], "0.0075")
67+
assert_equal(prices[3]['current_price'], "0.0075")
68+
69+
inbound_sms_prices = result.inbound_sms_prices
70+
71+
assert_equal(inbound_sms_prices[0]['number_type'], "local")
72+
assert_equal(inbound_sms_prices[0]['base_price'], "0.0075")
73+
assert_equal(inbound_sms_prices[0]['current_price'], "0.0075")
74+
75+
assert_equal(inbound_sms_prices[1]['number_type'], "shortcode")
76+
assert_equal(inbound_sms_prices[1]['base_price'], "0.0075")
77+
assert_equal(inbound_sms_prices[1]['current_price'], "0.005")
78+
79+
assert_equal(inbound_sms_prices[2]['number_type'], "toll-free")
80+
assert_equal(inbound_sms_prices[2]['base_price'], "0.0075")
81+
assert_equal(inbound_sms_prices[2]['current_price'], "0.0075")
82+
83+
request.assert_called_with(
84+
"GET",
85+
"{0}/Messaging/Countries/US".format(BASE_URI),
86+
auth=AUTH,
87+
use_json_extension=False,
88+
)

tests/resources/keys_instance.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sid":"SKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3+
"friendly_name":"Fuzzy Lumpkins' SigningKey",
4+
"date_created":"Fri, 13 Mar 2015 13:24:01 +0000",
5+
"date_updated":"Fri, 13 Mar 2015 13:24:01 +0000"
6+
}

tests/resources/keys_list.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"keys":[
3+
{
4+
"sid":"SK932e398ac43ca670b1609b05ee301e8c",
5+
"friendly_name":"Fuzzy Lumpkins' SigningKey",
6+
"date_created":"Fri, 13 Mar 2015 13:24:01 +0000",
7+
"date_updated":"Fri, 13 Mar 2015 13:24:01 +0000"
8+
}
9+
],
10+
"first_page_uri":"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Keys.json?PageSize=50&Page=0",
11+
"uri":"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Keys.json?PageSize=50&Page=0",
12+
"next_page_uri":null,
13+
"previous_page_uri":null,
14+
"page":0,
15+
"page_size":50,
16+
"start":0,
17+
"end":1
18+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"country": "United States",
3+
"iso_country": "US",
4+
"price_unit": "usd",
5+
"outbound_sms_prices": [
6+
{
7+
"mcc": "311",
8+
"mnc": "484",
9+
"carrier": "Verizon",
10+
"prices": [
11+
{
12+
"number_type": "mobile",
13+
"base_price": "0.0075",
14+
"current_price": "0.0070"
15+
},
16+
{
17+
"number_type": "local",
18+
"base_price": "0.0075",
19+
"current_price": "0.0070"
20+
},
21+
{
22+
"number_type": "shortcode",
23+
"base_price": "0.01",
24+
"current_price": "0.01"
25+
},
26+
{
27+
"number_type": "toll-free",
28+
"base_price": "0.0075",
29+
"current_price": "0.0075"
30+
}
31+
]
32+
}
33+
],
34+
"inbound_sms_prices": [
35+
{
36+
"number_type": "local",
37+
"base_price": "0.0075",
38+
"current_price": "0.0075"
39+
},
40+
{
41+
"number_type": "shortcode",
42+
"base_price": "0.0075",
43+
"current_price": "0.005"
44+
},
45+
{
46+
"number_type": "toll-free",
47+
"base_price": "0.0075",
48+
"current_price": "0.0075"
49+
}
50+
]
51+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"meta": {
3+
"first_page_url": "https://pricing.twilio.com/v1/Messaging/Countries?PageSize=50&Page=0",
4+
"key": "countries",
5+
"next_page_url": "https://pricing.twilio.com/v1/Messaging/Countries?PageSize=50&Page=1&PageToken=DNCZ",
6+
"page": 0,
7+
"page_size": 50,
8+
"previous_page_url": null,
9+
"url": "https://pricing.twilio.com/v1/Messaging/Countries?PageSize=50&Page=0"
10+
},
11+
"countries": [
12+
{
13+
"country": "Austria",
14+
"iso_country": "AT",
15+
"url": "https://pricing.twilio.com/v1/Messaging/Countries/AT"
16+
},
17+
{
18+
"country": "Australia",
19+
"iso_country": "AU",
20+
"url": "https://pricing.twilio.com/v1/Messaging/Countries/AU"
21+
}
22+
]
23+
}

tests/test_keys.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from mock import patch, Mock
2+
from twilio.rest.resources.keys import Keys, Key
3+
from tests.tools import create_mock_json
4+
5+
ACCOUNT_SID = "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
6+
AUTH = (ACCOUNT_SID, "token")
7+
BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/{0}".format(ACCOUNT_SID)
8+
KEY_SID = "SKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
9+
10+
list_resource = Keys(BASE_URL, AUTH)
11+
12+
13+
@patch("twilio.rest.resources.base.make_twilio_request")
14+
def test_get_key(mock):
15+
resp = create_mock_json("tests/resources/keys_instance.json")
16+
mock.return_value = resp
17+
18+
url = BASE_URL + "/Keys/{0}".format(KEY_SID)
19+
list_resource.get(KEY_SID)
20+
21+
mock.assert_called_with("GET", url, auth=AUTH, use_json_extension=True)
22+
23+
24+
@patch("twilio.rest.resources.base.make_twilio_request")
25+
def test_create_key(mock):
26+
resp = create_mock_json("tests/resources/keys_instance.json")
27+
resp.status_code = 201
28+
mock.return_value = resp
29+
30+
url = BASE_URL + "/Keys"
31+
list_resource.create(friendly_name="Fuzzy Lumpkins' SigningKey")
32+
params = {
33+
'FriendlyName': "Fuzzy Lumpkins' SigningKey"
34+
}
35+
36+
mock.assert_called_with("POST", url, data=params, auth=AUTH, use_json_extension=True)
37+
38+
39+
@patch("twilio.rest.resources.base.make_twilio_request")
40+
def test_update_key(mock):
41+
resp = create_mock_json("tests/resources/keys_instance.json")
42+
mock.return_value = resp
43+
44+
url = BASE_URL + "/Keys/{0}".format(KEY_SID)
45+
list_resource.update(sid=KEY_SID, friendly_name="Fuzzy Lumpkins' SigningKey")
46+
params = {
47+
'FriendlyName': "Fuzzy Lumpkins' SigningKey"
48+
}
49+
50+
mock.assert_called_with("POST", url, data=params, auth=AUTH, use_json_extension=True)
51+
52+
53+
@patch("twilio.rest.resources.base.Resource.request")
54+
def test_delete_key(mock):
55+
resp = Mock()
56+
resp.content = ""
57+
resp.status_code = 204
58+
mock.return_value = resp, {}
59+
60+
key = Key(list_resource, KEY_SID)
61+
key.delete()
62+
63+
url = BASE_URL + "/Keys/{0}".format(KEY_SID)
64+
mock.assert_called_with("DELETE", url)
65+
66+
67+
@patch("twilio.rest.resources.base.make_twilio_request")
68+
def test_list_keys(mock):
69+
resp = create_mock_json("tests/resources/keys_list.json")
70+
mock.return_value = resp
71+
72+
url = BASE_URL + "/Keys"
73+
list_resource.list()
74+
75+
mock.assert_called_with("GET", url, params={}, auth=AUTH, use_json_extension=True)

tests/test_recordings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ def test_paging(mock):
2727
use_json_extension=True)
2828

2929

30+
@patch("twilio.rest.resources.base.make_twilio_request")
31+
def test_paging_iter(mock):
32+
resp = create_mock_json("tests/resources/recordings_list.json")
33+
mock.return_value = resp
34+
35+
uri = "%s/Recordings" % (BASE_URI)
36+
37+
next(recordings.iter(before=date(2010, 12, 5)))
38+
exp_params = {'DateCreated<': '2010-12-05'}
39+
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
40+
use_json_extension=True)
41+
42+
next(recordings.iter(after=date(2012, 12, 7)))
43+
exp_params = {'DateCreated>': '2012-12-07'}
44+
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH,
45+
use_json_extension=True)
46+
47+
3048
@patch("twilio.rest.resources.base.make_twilio_request")
3149
def test_get(mock):
3250
resp = create_mock_json("tests/resources/recordings_instance.json")

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26, py27, py32, py33, py34, pypy
2+
envlist = py26, py27, py32, py33, py34, py35, pypy
33

44
[testenv]
55
deps= -r{toxinidir}/tests/requirements.txt

twilio/rest/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Conferences,
1212
ConnectApps,
1313
DependentPhoneNumbers,
14+
Keys,
1415
MediaList,
1516
Members,
1617
Messages,
@@ -74,6 +75,7 @@ def __init__(self, account=None, token=None, base="https://api.twilio.com",
7475
self.media = MediaList(self.account_uri, self.auth, timeout)
7576
self.sip = Sip(self.account_uri, self.auth, timeout)
7677
self.tokens = Tokens(self.account_uri, self.auth, timeout)
78+
self.keys = Keys(self.account_uri, self.auth, timeout)
7779

7880
def participants(self, conference_sid):
7981
"""

0 commit comments

Comments
 (0)
0