diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py index 84f772707ccd..72e0a4b4d47e 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_phone_numbers_client.py @@ -13,7 +13,6 @@ PhoneNumberCapabilitiesRequest, PhoneNumberPurchaseRequest, PhoneNumberType, - PhoneNumberAssignmentType ) from ._shared.utils import parse_connection_str, get_authentication_policy from ._version import SDK_MONIKER @@ -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 @@ -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, @@ -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] @@ -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 diff --git a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py index 18a00f35874a..007569cacc14 100644 --- a/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/aio/_phone_numbers_client_async.py @@ -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 @@ -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 @@ -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, @@ -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. @@ -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 diff --git a/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client.py b/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client.py index e3676ac27808..6e0f605ca012 100644 --- a/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client.py +++ b/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -297,21 +301,22 @@ 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 @@ -319,7 +324,7 @@ 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 diff --git a/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client_async.py b/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client_async.py index b95a9486b99e..9a119142606f 100644 --- a/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client_async.py +++ b/sdk/communication/azure-communication-phonenumbers/test/test_phone_number_administration_client_async.py @@ -30,6 +30,7 @@ "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"] @@ -37,11 +38,13 @@ 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 - + + @pytest.mark.asyncio class TestPhoneNumbersClientAsync(PhoneNumbersTestCase): def setup_method(self): @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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)