|
| 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 | + ) |
0 commit comments