Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
PhoneNumberCapabilitiesRequest,
PhoneNumberPurchaseRequest,
PhoneNumberType,
PhoneNumberAssignmentType
)
from ._shared.utils import parse_connection_str, get_authentication_policy
from ._version import SDK_MONIKER
Expand Down Expand Up @@ -55,7 +54,6 @@ def __init__(
self,
endpoint, # type: str
credential, # type: Union[TokenCredential, AzureKeyCredential]
accepted_language=None, # type: str
**kwargs # type: Any
):
# type: (...) -> None
Expand All @@ -70,7 +68,7 @@ def __init__(
"You need to provide account shared key to authenticate.")

self._endpoint = endpoint
self._accepted_language = accepted_language
self._accepted_language = kwargs.pop("accepted_language", None)
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION.value)
self._phone_number_client = PhoneNumbersClientGen(
self._endpoint,
Expand Down Expand Up @@ -386,8 +384,6 @@ def list_available_area_codes(
self,
country_code, # type: str
phone_number_type, # type: PhoneNumberType
assignment_type=None, # type: PhoneNumberAssignmentType
locality=None, # type: str
**kwargs # type: Any
):
# type: (...) -> ItemPaged[PhoneNumberAreaCode]
Expand Down Expand Up @@ -417,8 +413,10 @@ def list_available_area_codes(
return self._phone_number_client.phone_numbers.list_area_codes(
country_code,
phone_number_type=phone_number_type,
assignment_type=assignment_type,
locality=locality,
assignment_type=kwargs.pop(
"assignment_type", None),
locality=kwargs.pop(
"locality", None),
administrative_division=kwargs.pop(
"administrative_division", None),
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
from typing import TYPE_CHECKING, Union
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async
from azure.core.paging import ItemPaged
from azure.core.polling import LROPoller
from .._generated.aio._client import PhoneNumbersClient as PhoneNumbersClientGen
from .._generated.models import (
PhoneNumberSearchRequest,
PhoneNumberCapabilitiesRequest,
PhoneNumberPurchaseRequest,
PhoneNumberType,
PhoneNumberAssignmentType
)
from .._shared.utils import parse_connection_str, get_authentication_policy
from .._version import SDK_MONIKER
Expand Down Expand Up @@ -56,8 +53,7 @@ class PhoneNumbersClient(object):
def __init__(
self,
endpoint, # type: str
credential, # type: AsyncTokenCredential
accepted_language=None,
credential, # type: Union[AsyncTokenCredential, AzureKeyCredential]
**kwargs # type: Any
):
# type: (...) -> None
Expand All @@ -72,7 +68,7 @@ def __init__(
"You need to provide account shared key to authenticate.")

self._endpoint = endpoint
self._accepted_language = accepted_language
self._accepted_language = kwargs.pop("accepted_language", None)
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION.value)
self._phone_number_client = PhoneNumbersClientGen(
self._endpoint,
Expand Down Expand Up @@ -385,11 +381,9 @@ def list_available_area_codes(
self,
country_code, # type: str
phone_number_type, # type: PhoneNumberType
assignment_type=None, # type: PhoneNumberAssignmentType
locality=None, # type: str
**kwargs # type: Any
):
# type: (...) -> ItemPaged[PhoneNumberAreaCode]
# type: (...) -> AsyncItemPaged[PhoneNumberAreaCode]
"""Gets the list of available area codes.

:param country_code: The ISO 3166-2 country/region two letter code, e.g. US. Required.
Expand All @@ -416,8 +410,10 @@ def list_available_area_codes(
return self._phone_number_client.phone_numbers.list_area_codes(
country_code,
phone_number_type=phone_number_type,
assignment_type=assignment_type,
locality=locality,
assignment_type=kwargs.pop(
"assignment_type", None),
locality=kwargs.pop(
"locality", None),
administrative_division=kwargs.pop(
"administrative_division", None),
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ def _get_test_phone_number():
test_agent = os.environ["AZURE_TEST_AGENT"]
return os.environ["AZURE_PHONE_NUMBER_" + test_agent]


def is_client_error_status_code(
status_code # type: int
):
status_code # type: int
):
return status_code >= 400 and status_code < 500


Expand Down Expand Up @@ -225,7 +226,8 @@ def test_get_purchased_phone_number_with_invalid_phone_number(self, **kwargs):
with pytest.raises(Exception) as ex:
self.phone_number_client.get_purchased_phone_number(phone_number)

assert is_client_error_status_code(ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert is_client_error_status_code(
ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert ex.value.message is not None # type: ignore

@recorded_by_proxy
Expand Down Expand Up @@ -258,7 +260,8 @@ def test_update_phone_number_capabilities_with_unauthorized_number(self, **kwarg
PhoneNumberCapabilityType.INBOUND,
polling=True
)
assert is_client_error_status_code(ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert is_client_error_status_code(
ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert ex.value.message is not None # type: ignore

@recorded_by_proxy
Expand All @@ -275,7 +278,8 @@ def test_update_phone_number_capabilities_with_invalid_number(self, **kwargs):
PhoneNumberCapabilityType.INBOUND,
polling=True
)
assert is_client_error_status_code(ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert is_client_error_status_code(
ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert ex.value.message is not None # type: ignore

@recorded_by_proxy
Expand All @@ -297,29 +301,30 @@ def test_update_phone_number_capabilities_with_empty_number(self, **kwargs):
def test_list_toll_free_area_codes_from_managed_identity(self):
phone_number_client = self._get_managed_identity_phone_number_client()
area_codes = phone_number_client.list_available_area_codes(
"US", PhoneNumberType.TOLL_FREE, PhoneNumberAssignmentType.APPLICATION)
"US", PhoneNumberType.TOLL_FREE, assignment_type=PhoneNumberAssignmentType.APPLICATION)
assert area_codes.next()

@recorded_by_proxy
def test_list_toll_free_area_codes(self):
area_codes = self.phone_number_client.list_available_area_codes(
"US", PhoneNumberType.TOLL_FREE, PhoneNumberAssignmentType.APPLICATION)
"US", PhoneNumberType.TOLL_FREE, assignment_type=PhoneNumberAssignmentType.APPLICATION)
assert area_codes.next()

@recorded_by_proxy
def test_list_geographic_area_codes_from_managed_identity(self):
phone_number_client = self._get_managed_identity_phone_number_client()
first_locality = phone_number_client.list_available_localities("US").next()
first_locality = phone_number_client.list_available_localities(
"US").next()
area_codes = self.phone_number_client.list_available_area_codes(
"US", PhoneNumberType.GEOGRAPHIC, PhoneNumberAssignmentType.PERSON, first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
"US", PhoneNumberType.GEOGRAPHIC, assignment_type=PhoneNumberAssignmentType.PERSON, locality=first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
assert area_codes.next()

@recorded_by_proxy
def test_list_geographic_area_codes(self):
first_locality = self.phone_number_client.list_available_localities(
"US").next()
area_codes = self.phone_number_client.list_available_area_codes(
"US", PhoneNumberType.GEOGRAPHIC, PhoneNumberAssignmentType.PERSON, first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
"US", PhoneNumberType.GEOGRAPHIC, assignment_type=PhoneNumberAssignmentType.PERSON, locality=first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
assert area_codes.next()

@recorded_by_proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@
"COMMUNICATION_SKIP_CAPABILITIES_LIVE_TEST", "false") == "true"
SKIP_UPDATE_CAPABILITIES_TESTS_REASON = "Phone number capabilities are skipped."


def _get_test_phone_number():
if SKIP_UPDATE_CAPABILITIES_TESTS:
return os.environ["AZURE_PHONE_NUMBER"]

test_agent = os.environ["AZURE_TEST_AGENT"]
return os.environ["AZURE_PHONE_NUMBER_" + test_agent]


def is_client_error_status_code(
status_code # type: int
):
status_code # type: int
):
return status_code >= 400 and status_code < 500



@pytest.mark.asyncio
class TestPhoneNumbersClientAsync(PhoneNumbersTestCase):
def setup_method(self):
Expand Down Expand Up @@ -239,7 +242,8 @@ async def test_get_purchased_phone_number_with_invalid_phone_number(self):
async with self.phone_number_client:
await self.phone_number_client.get_purchased_phone_number(phone_number)

assert is_client_error_status_code(ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert is_client_error_status_code(
ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert ex.value.message is not None # type: ignore

@recorded_by_proxy_async
Expand Down Expand Up @@ -274,8 +278,9 @@ async def test_update_phone_number_capabilities_with_unauthorized_number(self):
PhoneNumberCapabilityType.INBOUND,
polling=True
)

assert is_client_error_status_code(ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore

assert is_client_error_status_code(
ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert ex.value.message is not None # type: ignore

@recorded_by_proxy_async
Expand All @@ -294,7 +299,8 @@ async def test_update_phone_number_capabilities_with_invalid_number(self):
polling=True
)

assert is_client_error_status_code(ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert is_client_error_status_code(
ex.value.status_code) is True, 'Status code {ex.value.status_code} does not indicate a client error' # type: ignore
assert ex.value.message is not None # type: ignore

@recorded_by_proxy_async
Expand All @@ -318,7 +324,7 @@ async def test_list_toll_free_area_codes_with_managed_identity(self):
phone_number_client = self._get_managed_identity_phone_number_client()
async with phone_number_client:
area_codes = phone_number_client.list_available_area_codes(
"US", PhoneNumberType.TOLL_FREE, PhoneNumberAssignmentType.APPLICATION)
"US", PhoneNumberType.TOLL_FREE, assignment_type=PhoneNumberAssignmentType.APPLICATION)
items = []
async for item in area_codes:
items.append(item)
Expand All @@ -328,7 +334,7 @@ async def test_list_toll_free_area_codes_with_managed_identity(self):
async def test_list_toll_free_area_codes(self):
async with self.phone_number_client:
area_codes = self.phone_number_client.list_available_area_codes(
"US", PhoneNumberType.TOLL_FREE, PhoneNumberAssignmentType.APPLICATION)
"US", PhoneNumberType.TOLL_FREE, assignment_type=PhoneNumberAssignmentType.APPLICATION)
items = []
async for item in area_codes:
items.append(item)
Expand All @@ -341,7 +347,7 @@ async def test_list_geographic_area_codes_with_managed_identity(self):
localities = phone_number_client.list_available_localities("US")
async for first_locality in localities:
area_codes = self.phone_number_client.list_available_area_codes(
"US", PhoneNumberType.GEOGRAPHIC, PhoneNumberAssignmentType.PERSON, first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
"US", PhoneNumberType.GEOGRAPHIC, assignment_type=PhoneNumberAssignmentType.PERSON, locality=first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
items = []
async for item in area_codes:
items.append(item)
Expand All @@ -355,7 +361,7 @@ async def test_list_geographic_area_codes(self):
"US")
async for first_locality in localities:
area_codes = self.phone_number_client.list_available_area_codes(
"US", PhoneNumberType.GEOGRAPHIC, PhoneNumberAssignmentType.PERSON, first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
"US", PhoneNumberType.GEOGRAPHIC, assignment_type=PhoneNumberAssignmentType.PERSON, locality=first_locality.localized_name, administrative_division=first_locality.administrative_division.abbreviated_name)
items = []
async for item in area_codes:
items.append(item)
Expand Down