8000 Add PhoneNumbers tests · damui/twilio-python@e0eed51 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0eed51

Browse files
committed
Add PhoneNumbers tests
1 parent 8e6e387 commit e0eed51

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

tests/pricing/test_numbers.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.phone_numbers import PhoneNumberCountries
8+
9+
10+
AUTH = ("AC123", "token")
11+
BASE_URI = "https://pricing.twilio.com/v1"
12+
13+
14+
class NumbersTest(unittest.TestCase):
15+
16+
@patch('twilio.rest.resources.base.make_twilio_request')
17+
def test_number_countries(self, request):
18+
resp = create_mock_json('tests/resources/pricing/phone_number_country_list.json')
19+
resp.status_code = 200
20+
request.return_value = resp
21+
22+
countries = PhoneNumberCountries(BASE_URI + "/PhoneNumbers", AUTH)
23+
result = countries.list()
24+
25+
assert_equal(result[0].iso_country, "AC")
26+
assert_equal(len(result), 3)
27+
28+
request.assert_called_with(
29+
"GET",
30+
"{}/PhoneNumbers/Countries".format(BASE_URI),
31+
auth=AUTH,
32+
)
33+
34+
@patch('twilio.rest.resources.base.make_twilio_request')
35+
def test_number_country(self, request):
36+
resp = create_mock_json('tests/resources/pricing/phone_number_country_instance.json')
37+
resp.status_code = 200
38+
request.return_value = resp
39+
40+
countries = PhoneNumberCountries(BASE_URI + "/PhoneNumbers", AUTH)
41+
country = countries.get('EE')
42+
43+
assert_equal(country.country, "Estonia")
44+
assert_equal(
45+
country.phone_number_prices,
46+
[
47+
{
48+
'type': 'mobile',
49+
'base_price': 3.00,
50+
'current_price': 3.00,
51+
},
52+
{
53+
'type': 'national',
54+
'base_price': 1.00,
55+
'current_price': 1.00,
56+
}
57+
],
58+
)
59+
60+
request.assert_called_with(
61+
"GET",
62+
"{}/PhoneNumbers/Countries/EE".format(BASE_URI),
63+
auth=AUTH,
64+
)

tests/resources/pricing/phone_number_country_instance.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries/EE"
3-
"country : "Estonia"
2+
"uri": "pricing.twilio.com/v1/PhoneNumbers/Countries/EE",
3+
"country" : "Estonia",
44
"iso_country": "EE",
55
"phone_number_prices": [
66
{

0 commit comments

Comments
 (0)
0