Exemplo n.º 1
0
 def test_list_all_phone_numbers_from_managed_identity(self):
     endpoint, access_key = parse_connection_str(self.connection_str)
     credential = create_token_credential()
     phone_number_client = PhoneNumbersAdministrationClient(
         endpoint, credential)
     pages = phone_number_client.list_all_phone_numbers()
     assert pages.next()
FILE: phone_number_configuration_sample.py
DESCRIPTION:
    This sample demonstrates how to configure phone numbers and get phone number configuration via a connection string and phone number to configure
USAGE:
    python phone_number_configuration_sample.py
    Set the environment variables with your own values before running the sample:
    1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The endpoint of your Azure Communication Service
    2) AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE - The phone number you want to configure
"""

import os
from azure.communication.phonenumbers import (PhoneNumbersAdministrationClient,
                                              PstnConfiguration)

connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
phone_number_administration_client = PhoneNumbersAdministrationClient.from_connection_string(
    connection_str)
phonenumber_to_configure = os.getenv(
    'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_PHONENUMBER_TO_CONFIGURE',
    "phonenumber_to_configure")


def get_number_configuration():
    # [START get_number_configuration]
    phone_number_configuration_response = phone_number_administration_client.get_number_configuration(
        phone_number=phonenumber_to_configure)
    # [END get_number_configuration]
    print('phone_number_configuration_response:')
    print(phone_number_configuration_response)


def configure_number():
Exemplo n.º 3
0
 def setUp(self):
     super(PhoneNumbersAdministrationClientTest, self).setUp()
     self.recording_processors.extend([
         BodyReplacerProcessor(keys=[
             "id", "token", "capabilitiesUpdateId", "phoneNumber",
             "phonePlanIds", "phoneNumberCapabilitiesUpdates", "releaseId",
             "phoneNumberReleaseStatusDetails", "searchId", "phoneNumbers",
             "entities", "phonePlanGroups", "phonePlans",
             "phoneNumberCapabilitiesUpdate"
         ]),
         PhoneNumberUriReplacer()
     ])
     self._phone_number_administration_client = PhoneNumbersAdministrationClient.from_connection_string(
         self.connection_str)
     if self.is_live:
         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_reservation = os.getenv(
             'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_AREA_CODE_FOR_RESERVATION'
         )
         self.reservation_id = os.getenv(
             'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID')
         self.reservation_id_to_purchase = os.getenv(
             'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_ID_TO_PURCHASE'
         )
         self.reservation_id_to_cancel = os.getenv(
             'AZURE_COMMUNICATION_SERVICE_PHONENUMBERS_RESERVATION_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")
         self.scrubber.register_name_pair(self.phone_plan_id,
                                          "phone_plan_id")
         self.scrubber.register_name_pair(self.phone_plan_id_area_codes,
                                          "phone_plan_id_area_codes")
         self.scrubber.register_name_pair(self.area_code_for_reservation,
                                          "area_code_for_reservation")
         self.scrubber.register_name_pair(self.reservation_id,
                                          "reservation_id")
         self.scrubber.register_name_pair(self.reservation_id_to_purchase,
                                          "reservation_id_to_purchase")
         self.scrubber.register_name_pair(self.reservation_id_to_cancel,
                                          "reservation_id_to_cancel")
         self.scrubber.register_name_pair(self.phonenumber_to_configure,
                                          "phonenumber_to_configure")
         self.scrubber.register_name_pair(self.phonenumber_to_get_config,
                                          "phonenumber_to_get_config")
         self.scrubber.register_name_pair(self.phonenumber_to_unconfigure,
                                          "phonenumber_to_unconfigure")
         self.scrubber.register_name_pair(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")
         self.scrubber.register_name_pair(self.release_id, "release_id")
     else:
         self.connection_str = "endpoint=https://sanitized.communication.azure.com/;accesskey=fake==="
         self.country_code = "US"
         self.locale = "en-us"
         self.phone_plan_group_id = "phone_plan_group_id"
         self.phone_plan_id = "phone_plan_id"
         self.phone_plan_id_area_codes = "phone_plan_id_area_codes"
         self.area_code_for_reservation = "area_code_for_reservation"
         self.reservation_id = "reservation_id"
         self.reservation_id_to_purchase = "reservation_id_to_purchase"
         self.reservation_id_to_cancel = "reservation_id_to_cancel"
         self.phonenumber_to_configure = "phonenumber_to_configure"
         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"