From 6a0d47dd3fab0a9dcc640d9c39516fb533fd65eb Mon Sep 17 00:00:00 2001 From: Eason Date: Fri, 2 Oct 2020 00:51:01 -0700 Subject: [PATCH 1/4] Azure Communication Service - Phone Number Administration - Samples (#14162) * add tnm samples v0 * address comments * update samples with long run operation * add basic readme for phone number description * add e=code example to tnm readme * update admin setup.py with long_description_content_type Co-authored-by: Eason Yang --- .../README.md | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/sdk/communication/azure-communication-administration/README.md b/sdk/communication/azure-communication-administration/README.md index ebab042214b2..1fae817acda1 100644 --- a/sdk/communication/azure-communication-administration/README.md +++ b/sdk/communication/azure-communication-administration/README.md @@ -184,6 +184,135 @@ def purchase_search(): ) ``` +##Communication Phone number +### Get Countries + +```python +def list_all_supported_countries(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + + supported_countries = phone_number_administration_client.list_all_supported_countries() + for supported_country in supported_countries: + print(supported_country) +``` + +### Get Phone Plan Groups + +Phone plan groups come in two types, Geographic and Toll-Free. + +```python +def list_phone_plan_groups(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + + phone_plan_groups_response = phone_number_administration_client.list_phone_plan_groups( + country_code=country_code + ) + for phone_plan_group in phone_plan_groups_response: + print(phone_plan_group) +``` + +### Get Phone Plans + +Unlike Toll-Free phone plans, area codes for Geographic Phone Plans are empty. Area codes are found in the Area Codes API. + +```python +def list_phone_plans(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") + + phone_plans_response = phone_number_administration_client.list_phone_plans( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id + ) + for phone_plan in phone_plans_response: + print(phone_plan) +``` + +### Get Location Options + +For Geographic phone plans, you can query the available geographic locations. The locations options are structured like the geographic hierarchy of a country. For example, the US has states and within each state are cities. + +```python +def get_phone_plan_location_options(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") + phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") + + location_options_response = phone_number_administration_client.get_phone_plan_location_options( + country_code=country_code, + phone_plan_group_id=phone_plan_group_id, + phone_plan_id=phone_plan_id + ) + print(location_options_response) +``` + +### Get Area Codes + +Fetching area codes for geographic phone plans will require the the location options queries set. You must include the chain of geographic locations traversing down the location options object returned by the GetLocationOptions API. + +```python +def get_all_area_codes(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") + phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") + + all_area_codes = phone_number_administration_client.get_all_area_codes( + location_type="NotRequired", + country_code=country_code, + phone_plan_id=phone_plan_id_area_codes + ) + print(all_area_codes) +``` + +### Create Search + +```python +def create_search(): + from azure.communication.administration import CreateSearchOptions + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") + area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH', "area-code") + + searchOptions = CreateSearchOptions( + area_code=area_code_for_search, + description="testsearch20200014", + display_name="testsearch20200014", + phone_plan_ids=[phone_plan_id], + quantity=1 + ) + search_response = phone_number_administration_client.begin_create_search( + body=searchOptions + ) + print(search_response.status()) +``` + +### Get search by id +```python +def get_search_by_id(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID', "search-id") + + phone_number_search_response = phone_number_administration_client.get_search_by_id( + search_id=search_id + ) + print(phone_number_search_response) +``` + +### Purchase Search + +```python +def purchase_search(): + phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) + search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE', "search-id") + + phone_number_administration_client.begin_purchase_search( + search_id=search_id_to_purchase + ) +``` + # Troubleshooting The Azure Communication Service Identity client will raise exceptions defined in [Azure Core][azure_core]. From 0564ef22a8b7c882bd6677bebafbf4bc539f0657 Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Fri, 2 Oct 2020 14:14:35 -0700 Subject: [PATCH 2/4] rename live tests variables --- .../tests/test_phone_number_administration_client.py | 7 +++---- .../tests/test_phone_number_administration_client_async.py | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py index 90b6b50f35ec..0fb79fb83be4 100644 --- a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py +++ b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py @@ -160,7 +160,7 @@ def test_list_all_supported_countries(self): @pytest.mark.live_test_only def test_get_number_configuration(self): phone_number_response = self._phone_number_administration_client.get_number_configuration( - phone_number=self.phonenumber_to_unconfigure + phone_number=self.phonenumber_to_get_config ) assert phone_number_response.pstn_configuration @@ -168,12 +168,11 @@ def test_get_number_configuration(self): def test_configure_number(self): pstnConfig = PstnConfiguration( callback_url="https://callbackurl", - application_id="ApplicationId", - azure_pstn_target_id="AzurePstnTargetId" + application_id="ApplicationId" ) configure_number_response = self._phone_number_administration_client.configure_number( pstn_configuration=pstnConfig, - phone_number=self.phonenumber_to_unconfigure + phone_number=self.phonenumber_to_configure ) assert not configure_number_response diff --git a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py index 178515f52e04..17c618825c1f 100644 --- a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py +++ b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py @@ -190,8 +190,7 @@ async def test_get_number_configuration(self): async def test_configure_number(self): pstnConfig = PstnConfiguration( callback_url="https://callbackurl", - application_id="ApplicationId", - azure_pstn_target_id="AzurePstnTargetId" + application_id="ApplicationId" ) async with self._phone_number_administration_client: configure_number_response = await self._phone_number_administration_client.configure_number( From 5a46934a2da2c96f1fe10a545806321a6e8415a4 Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Fri, 2 Oct 2020 15:30:31 -0700 Subject: [PATCH 3/4] add release phone numbers --- ...ion_client.test_release_phone_numbers.yaml | 39 ++++++++++++++++ ...ient_async.test_release_phone_numbers.yaml | 31 +++++++++++++ ...test_phone_number_administration_client.py | 43 +++++++++++------- ...hone_number_administration_client_async.py | 45 ++++++++++++------- 4 files changed, 128 insertions(+), 30 deletions(-) create mode 100644 sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_release_phone_numbers.yaml create mode 100644 sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_release_phone_numbers.yaml diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_release_phone_numbers.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_release_phone_numbers.yaml new file mode 100644 index 000000000000..6523c0d0d697 --- /dev/null +++ b/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_release_phone_numbers.yaml @@ -0,0 +1,39 @@ +interactions: +- request: + body: '{"phoneNumbers": "sanitized"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '34' + Content-Type: + - application/json + Date: + - Fri, 02 Oct 2020 22:26:28 GMT + User-Agent: + - azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://sanitized.communication.azure.com/administration/phonenumbers/releases?api-version=2020-07-20-preview1 + response: + body: '{"releaseId": "sanitized"}' + headers: + content-type: + - application/json; charset=utf-8 + date: + - Fri, 02 Oct 2020 22:26:27 GMT + ms-cv: + - NlxnpgC8uU2r3FctCKo4VA.0 + transfer-encoding: + - chunked + x-processing-time: + - 735ms + status: + code: 200 + message: OK +version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_release_phone_numbers.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_release_phone_numbers.yaml new file mode 100644 index 000000000000..555ece0bf35d --- /dev/null +++ b/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_release_phone_numbers.yaml @@ -0,0 +1,31 @@ +interactions: +- request: + body: '{"phoneNumbers": "sanitized"}' + headers: + Accept: + - application/json + Content-Length: + - '34' + Content-Type: + - application/json + Date: + - Fri, 02 Oct 2020 22:24:33 GMT + User-Agent: + - azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://sanitized.communication.azure.com/administration/phonenumbers/releases?api-version=2020-07-20-preview1 + response: + body: '{"releaseId": "sanitized"}' + headers: + content-type: application/json; charset=utf-8 + date: Fri, 02 Oct 2020 22:24:32 GMT + ms-cv: m6zSFyuKqkaYNOWKqeSZRg.0 + transfer-encoding: chunked + x-processing-time: 606ms + status: + code: 200 + message: OK + url: https://sanitized.communication.azure.com/administration/phonenumbers/releases?api-version=2020-07-20-preview1 +version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py index 0fb79fb83be4..2f09606584ae 100644 --- a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py +++ b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py @@ -33,21 +33,22 @@ def setUp(self): self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( self.connection_str) if self.is_live: - self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE') - self.locale = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_LOCALE') - self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_GROUP_ID') - self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID') - self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES') - self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_AREA_CODE_FOR_SEARCH') - self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID') - self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_PURCHASE') - self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_CANCEL') - self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE') - self.phonenumber_to_get_config = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_GET_CONFIG') - self.phonenumber_to_unconfigure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_UNCONFIGURE') - self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES') - self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID') - self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_RELEASE_ID') + self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE') + self.locale = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_LOCALE') + self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID') + self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID') + self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES') + self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH') + self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID') + self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE') + self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_CANCEL') + self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE') + self.phonenumber_to_get_config = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_GET_CONFIG') + self.phonenumber_to_unconfigure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_UNCONFIGURE') + self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES') + self.phonenumber_to_release = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_RELEASE') + self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID') + self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RELEASE_ID') self.scrubber.register_name_pair( self.phone_plan_group_id, "phone_plan_group_id" @@ -92,6 +93,10 @@ def setUp(self): self.phonenumber_for_capabilities, "phonenumber_for_capabilities" ) + self.scrubber.register_name_pair( + self.phonenumber_to_release, + "phonenumber_to_release" + ) self.scrubber.register_name_pair( self.capabilities_id, "capabilities_id" @@ -115,6 +120,7 @@ def setUp(self): self.phonenumber_to_get_config = "phonenumber_to_get_config" self.phonenumber_to_unconfigure = "phonenumber_to_unconfigure" self.phonenumber_for_capabilities = "phonenumber_for_capabilities" + self.phonenumber_to_release = "phonenumber_to_release" self.capabilities_id = "capabilities_id" self.release_id = "release_id" @@ -212,6 +218,13 @@ def test_list_all_releases(self): releases_response = self._phone_number_administration_client.list_all_releases() assert releases_response.next().id + @pytest.mark.live_test_only + def test_release_phone_numbers(self): + releases_response = self._phone_number_administration_client.release_phone_numbers( + [self.phonenumber_to_release] + ) + assert releases_response.release_id + @pytest.mark.live_test_only def test_get_search_by_id(self): phone_number_search_response = self._phone_number_administration_client.get_search_by_id( diff --git a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py index 17c618825c1f..f831124390d0 100644 --- a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py +++ b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py @@ -34,21 +34,22 @@ def setUp(self): self._phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string( self.connection_str) if self.is_live: - self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_COUNTRY_CODE') - self.locale = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_LOCALE') - self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_GROUP_ID') - self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID') - self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONE_PLAN_ID_AREA_CODES') - self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_AREA_CODE_FOR_SEARCH') - self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID') - self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_PURCHASE') - self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_SEARCH_ID_TO_CANCEL') - self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_CONFIGURE') - self.phonenumber_to_get_config = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_GET_CONFIG') - self.phonenumber_to_unconfigure = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_TO_UNCONFIGURE') - self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_PHONENUMBER_FOR_CAPABILITIES') - self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_CAPABILITIES_ID') - self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_TNM_RELEASE_ID') + self.country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE') + self.locale = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_LOCALE') + self.phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID') + self.phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID') + self.phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES') + self.area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH') + self.search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID') + self.search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE') + self.search_id_to_cancel = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_CANCEL') + self.phonenumber_to_configure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE') + self.phonenumber_to_get_config = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_GET_CONFIG') + self.phonenumber_to_unconfigure = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_UNCONFIGURE') + self.phonenumber_for_capabilities = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_FOR_CAPABILITIES') + self.phonenumber_to_release = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_RELEASE') + self.capabilities_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_CAPABILITIES_ID') + self.release_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RELEASE_ID') self.scrubber.register_name_pair( self.phone_plan_group_id, "phone_plan_group_id" @@ -93,6 +94,10 @@ def setUp(self): self.phonenumber_for_capabilities, "phonenumber_for_capabilities" ) + self.scrubber.register_name_pair( + self.phonenumber_to_release, + "phonenumber_to_release" + ) self.scrubber.register_name_pair( self.capabilities_id, "capabilities_id" @@ -116,6 +121,7 @@ def setUp(self): self.phonenumber_to_get_config = "phonenumber_to_get_config" self.phonenumber_to_unconfigure = "phonenumber_to_unconfigure" self.phonenumber_for_capabilities = "phonenumber_for_capabilities" + self.phonenumber_to_release = "phonenumber_to_release" self.capabilities_id = "capabilities_id" self.release_id = "release_id" @@ -260,6 +266,15 @@ async def test_list_all_releases(self): self.assertGreater(len(items), 0) assert items[0].id + @AsyncCommunicationTestCase.await_prepared_test + @pytest.mark.live_test_only + async def test_release_phone_numbers(self): + async with self._phone_number_administration_client: + releases_response = await self._phone_number_administration_client.release_phone_numbers( + [self.phonenumber_to_release] + ) + assert releases_response.release_id + @AsyncCommunicationTestCase.await_prepared_test @pytest.mark.live_test_only async def test_get_search_by_id(self): From 6d9e4d2f06b01dbfaa4e5a08c14d6f4a70242878 Mon Sep 17 00:00:00 2001 From: Eason Yang Date: Fri, 2 Oct 2020 17:08:12 -0700 Subject: [PATCH 4/4] remove extra lines readme --- .../README.md | 129 ------------------ 1 file changed, 129 deletions(-) diff --git a/sdk/communication/azure-communication-administration/README.md b/sdk/communication/azure-communication-administration/README.md index 1fae817acda1..ebab042214b2 100644 --- a/sdk/communication/azure-communication-administration/README.md +++ b/sdk/communication/azure-communication-administration/README.md @@ -184,135 +184,6 @@ def purchase_search(): ) ``` -##Communication Phone number -### Get Countries - -```python -def list_all_supported_countries(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - - supported_countries = phone_number_administration_client.list_all_supported_countries() - for supported_country in supported_countries: - print(supported_country) -``` - -### Get Phone Plan Groups - -Phone plan groups come in two types, Geographic and Toll-Free. - -```python -def list_phone_plan_groups(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") - - phone_plan_groups_response = phone_number_administration_client.list_phone_plan_groups( - country_code=country_code - ) - for phone_plan_group in phone_plan_groups_response: - print(phone_plan_group) -``` - -### Get Phone Plans - -Unlike Toll-Free phone plans, area codes for Geographic Phone Plans are empty. Area codes are found in the Area Codes API. - -```python -def list_phone_plans(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") - phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") - - phone_plans_response = phone_number_administration_client.list_phone_plans( - country_code=country_code, - phone_plan_group_id=phone_plan_group_id - ) - for phone_plan in phone_plans_response: - print(phone_plan) -``` - -### Get Location Options - -For Geographic phone plans, you can query the available geographic locations. The locations options are structured like the geographic hierarchy of a country. For example, the US has states and within each state are cities. - -```python -def get_phone_plan_location_options(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") - phone_plan_group_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_GROUP_ID', "phone-plan-group-id") - phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") - - location_options_response = phone_number_administration_client.get_phone_plan_location_options( - country_code=country_code, - phone_plan_group_id=phone_plan_group_id, - phone_plan_id=phone_plan_id - ) - print(location_options_response) -``` - -### Get Area Codes - -Fetching area codes for geographic phone plans will require the the location options queries set. You must include the chain of geographic locations traversing down the location options object returned by the GetLocationOptions API. - -```python -def get_all_area_codes(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - country_code = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_COUNTRY_CODE', "US") - phone_plan_id_area_codes = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID_AREA_CODES', "phone-plan-id") - - all_area_codes = phone_number_administration_client.get_all_area_codes( - location_type="NotRequired", - country_code=country_code, - phone_plan_id=phone_plan_id_area_codes - ) - print(all_area_codes) -``` - -### Create Search - -```python -def create_search(): - from azure.communication.administration import CreateSearchOptions - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - phone_plan_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONE_PLAN_ID', "phone-plan-id") - area_code_for_search = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_SEARCH', "area-code") - - searchOptions = CreateSearchOptions( - area_code=area_code_for_search, - description="testsearch20200014", - display_name="testsearch20200014", - phone_plan_ids=[phone_plan_id], - quantity=1 - ) - search_response = phone_number_administration_client.begin_create_search( - body=searchOptions - ) - print(search_response.status()) -``` - -### Get search by id -```python -def get_search_by_id(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - search_id = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID', "search-id") - - phone_number_search_response = phone_number_administration_client.get_search_by_id( - search_id=search_id - ) - print(phone_number_search_response) -``` - -### Purchase Search - -```python -def purchase_search(): - phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) - search_id_to_purchase = os.getenv('AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_SEARCH_ID_TO_PURCHASE', "search-id") - - phone_number_administration_client.begin_purchase_search( - search_id=search_id_to_purchase - ) -``` - # Troubleshooting The Azure Communication Service Identity client will raise exceptions defined in [Azure Core][azure_core].