8000 Add voice pricing tests · damui/twilio-python@8e6e387 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e6e387

Browse files
committed
Add voice pricing tests
1 parent 602bd2c commit 8e6e387

File tree

9 files changed

+208
-8
lines changed
Filter options

9 files changed

+208
-8
lines changed

tests/pricing/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/pricing/test_voice.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import unittest
2+
from nose.tools import assert_equal
3+
4+
from mock import patch, ANY
5+
from tests.tools import create_mock_json
6+
7+
from twilio.rest.resources.pricing.voice import (
8+
VoiceCountries,
9+
VoiceCountry,
10+
VoiceNumber,
11+
VoiceNumbers,
12+
)
13+
14+
15+
AUTH = ("AC123", "token")
16+
BASE_URI = "https://pricing.twilio.com/v1"
17+
18+
19+
class VoiceTest(unittest.TestCase):
20+
21+
@patch('twilio.rest.resources.base.make_twilio_request')
22+
def test_voice_countries(self, request):
23+
resp = create_mock_json('tests/resources/pricing/voice_countries_list.json')
24+
resp.status_code = 200
25+
request.return_value = resp
26+
27+
countries = VoiceCountries(BASE_URI + "/Voice", AUTH)
28+
result = countries.list()
29+
30+
assert_equal(result[0].iso_country, "AC")
31+
assert_equal(len(result), 3)
32+
33+
request.assert_called_with(
34+
"GET",
35+
"{}/Voice/Countries".format(BASE_URI),
36+
auth=AUTH,
37+
)
38+
39+
@patch('twilio.rest.resources.base.make_twilio_request')
40+
def test_voice_country(self, request):
41+
resp = create_mock_json('tests/resources/pricing/voice_country_instance.json')
42+
resp.status_code = 200
43+
request.return_value = resp
44+
45+
countries = VoiceCountries(BASE_URI + "/Voice", AUTH)
46+
country = countries.get('EE')
47+
48+
assert_equal(country.country, "Estonia")
49+
assert_equal(
50+
country.inbound_call_prices[0],
51+
{
52+
'number_type': 'mobile',
53+
'call_base_price': 0.0075,
54+
'call_current_price': 0.0070
55+
},
56+
)
57+
58+
request.assert_called_with(
59+
"GET",
60+
"{}/Voice/Countries/EE".format(BASE_URI),
61+
auth=AUTH,
62+
)
63+
64+
@patch('twilio.rest.resources.base.make_twilio_request')
65+
def test_voice_number(self, request):
66+
resp = create_mock_json('tests/resources/pricing/voice_number_instance.json')
67+
resp.status_code = 200
68+
request.return_value = resp
69+
70+
numbers = VoiceNumbers(BASE_URI + "/Voice", AUTH)
71+
result = numbers.get('+14089673429')
72+
73+
assert_equal(result.number, '+14089673429')
74+
assert_equal(result.price_unit, 'usd')
75+
76+
request.assert_called_with(
77+
"GET",
78+
"{}/Voice/Numbers/+14089673429".format(BASE_URI),
79+
auth=AUTH,
80+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries/EE"
3+
"country” : "Estonia"
4+
"iso_country": "EE",
5+
"phone_number_prices": [
6+
{
7+
"type": "mobile",
8+
"base_price": 3.00,
9+
"current_price": 3.00
10+
},
11+
{
12+
"type": "national",
13+
"base_price": 1.00,
14+
"current_price": 1.00
15+
}
16+
],
17+
"price_unit": "usd"
18+
}
Lines changed: 20 add F438 itions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries",
3+
"countries": [
4+
{
5+
"country": "Ascension",
6+
"iso_country": "AC",
7+
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries/AC"
8+
},
9+
{
10+
"country": "Andorra",
11+
"iso_country": "AD",
12+
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries/AD"
13+
},
14+
{
15+
"country": "United States",
16+
"iso_country": "US",
17+
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries/US"
18+
}
19+
]
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"uri": "pricing.twilio.com/v1/Voice/Countries",
3+
"countries": [
4+
{
5+
"country": "Ascension",
6+
"iso_country": "AC",
7+
"uri": "pricing.twilio.com/v1/Voice/Countries/AC"
8+
},
9+
{
10+
"country": "Andorra",
11+
"iso_country": "AD",
12+
"uri": "pricing.twilio.com/v1/Voice/Countries/AD"
13+
},
14+
{
15+
"country": "United States",
16+
"iso_country": "US",
17+
"uri": "pricing.twilio.com/v1/Voice/Countries/US"
18+
}
19+
]
20+
}
21+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"uri": "pricing.twilio.com/v1/Voice/Countries/EE",
3+
"country" : "Estonia",
4+
"iso_country": "EE",
5+
"outbound_prefix_prices": [
6+
{
7+
"prefix_list": ["372"],
8+
"friendly_name": "Programmable Outbound Minute - Estonia",
9+
"call_base_price": 0.033,
10+
"call_current_price": 0.030
11+
},
12+
{
13+
"prefix_list": ["3725"],
14+
"friendly_name": "Programmable Outbound Minute - Mobile",
15+
"call_base_price": 0.0575,
16+
"call_current_price": 0.0575
17+
},
18+
{
19+
"prefixes": ["37240", "37270", "37281", "37282"],
20+
"friendly_name": "Programmable Outbound Minute - Other",
21+
"call_base_price": 0.465,
22+
"call_current_price": 0.465
23+
}
24+
],
25+
"inbound_call_prices": [
26+
{
27+
"number_type": "mobile",
28+
"call_base_price": 0.0075,
29+
"call_current_price": 0.0070
30+
},
31+
{
32+
"number_type": "national",
33+
"call_base_price": 0.0075,
34+
"call_current_price": 0.0070
35+
}
36+
],
37+
"price_unit": "usd"
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"uri": "pricing.twilio.com/v1/Voice/Numbers/+14089673429",
3+
"number": "+14089673429",
4+
"country": "United States",
5+
"iso_country" : "US",
6+
"outbound_call_price": {
7+
"call_base_price": 0.015,
8+
"call_current_price": 0.015
9+
},
10+
"inbound_call_price": {
11+
"number_type" : "local",
12+
"call_base_price": 0.0075,
13+
"call_current_price": 0.0070
14+
},
15+
"price_unit": "usd"
16+
}

tests/test_client.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
class RestClientTest(unittest.TestCase):
1414
def setUp(self):
1515
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN")
16-
self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID", "AUTH_TOKEN")
16+
self.task_router_client = TwilioTaskRouterClient("ACCOUNT_SID",
17+
"AUTH_TOKEN")
1718

1819
@patch("twilio.rest.base.make_request")
1920
def test_request(self, mock):
@@ -28,7 +29,8 @@ def test_request(self, mock):
2829
)
2930

3031
def test_connect_apps(self):
31-
assert_true(isinstance(self.client.connect_apps, resources.ConnectApps))
32+
assert_true(isinstance(self.client.connect_apps,
33+
resources.ConnectApps))
3234

3335
def test_authorized_apps(self):
3436
assert_true(isinstance(self.client.authorized_connect_apps,
@@ -46,24 +48,29 @@ def test_members(self, mock):
4648
resp = create_mock_json("tests/resources/members_list.json")
4749
mock.return_value = resp
4850
self.client.members("QU123").list()
49-
uri = "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID/Queues/QU123/Members"
51+
uri = "https://api.twilio.com/2010-04-01/Accounts/ACCOUNT_SID" \
52+
"/Queues/QU123/Members"
5053
mock.assert_called_with("GET", uri, params={}, auth=AUTH,
5154
use_json_extension=True)
5255

5356
@patch("twilio.rest.resources.base.make_request")
5457
def test_workflows(self, request):
55-
resp = create_mock_json("tests/resources/task_router/workflows_list.json")
58+
resp = create_mock_json(
59+
"tests/resources/task_router/workflows_list.json"
60+
)
5661
request.return_value = resp
5762
workflows = self.task_router_client.workflows("WS123")
5863
workflows = workflows.list()
5964
assert_true(workflows[0].sid is not None)
6065
uri = "https://taskrouter.twilio.com/v1/Workspaces/WS123/Workflows"
61-
request.assert_called_with("GET", uri, headers=ANY, params={}, auth=AUTH)
66+
request.assert_called_with("GET", uri, headers=ANY, params={},
67+
auth=AUTH)
6268

6369

6470
class RestClientTimeoutTest(unittest.TestCase):
6571
def setUp(self):
66-
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN", timeout=sentinel.timeout)
72+
self.client = TwilioRestClient("ACCOUNT_SID", "AUTH_TOKEN",
73+
timeout=sentinel.timeout)
6774

6875
@patch("twilio.rest.resources.base.make_twilio_request")
6976
def test_members(self, mock_request):

twilio/rest/resources/pricing/voice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def get(self, iso_country):
7171

7272
def list(self):
7373
"""Retrieve the list of countries in which Twilio Voice is available."""
74-
7574
resp, page = self.request("GET", self.uri)
7675

7776
return [self.load_instance(i) for i in page[self.key]]
@@ -112,7 +111,7 @@ class VoiceNumber(InstanceResource):
112111
discounts, etc.) to receive a call to this number
113112
"""
114113

115-
id_key = "phone_number"
114+
id_key = "number"
116115

117116

118117
class VoiceNumbers(ListResource):

0 commit comments

Comments
 (0)
0