Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,44 @@ def test_play_media_in_a_call(self):
self.terminate_call(unique_id)
return

@recorded_by_proxy
def test_dtmf_actions_in_a_call(self):
# try to establish the call
purchased_numbers = list(self.phonenumber_client.list_purchased_phone_numbers())
if len(purchased_numbers) >= 2:
caller = PhoneNumberIdentifier(purchased_numbers[0].phone_number)
target = PhoneNumberIdentifier(purchased_numbers[1].phone_number)
else:
raise ValueError("Invalid PSTN setup, test needs at least 2 phone numbers")

unique_id, call_connection, _ = self.establish_callconnection_pstn(caller, target)

# check returned events
connected_event = self.check_for_event('CallConnected', call_connection._call_connection_id, timedelta(seconds=15))
participant_updated_event = self.check_for_event('ParticipantsUpdated', call_connection._call_connection_id, timedelta(seconds=15))

if connected_event is None:
raise ValueError("Caller CallConnected event is None")
if participant_updated_event is None:
raise ValueError("Caller ParticipantsUpdated event is None")

call_connection.start_continuous_dtmf_recognition(target_participant=target)

# send DTMF tones
call_connection.send_dtmf_tones(tones=[DtmfTone.POUND], target_participant=target)
send_dtmf_completed_event = self.check_for_event('SendDtmfTonesCompleted', call_connection._call_connection_id, timedelta(seconds=15),)
if send_dtmf_completed_event is None:
raise ValueError("SendDtmfTonesCompleted event is None")

# stop continuous DTMF recognition
call_connection.stop_continuous_dtmf_recognition(target_participant=target)
continuous_dtmf_recognition_stopped_event = self.check_for_event('ContinuousDtmfRecognitionStopped', call_connection._call_connection_id, timedelta(seconds=15))
if continuous_dtmf_recognition_stopped_event is None:
raise ValueError("ContinuousDtmfRecognitionStopped event is None")

self.terminate_call(unique_id)
return
# NOTE: Commented out by ericasp in March 2024. This test is incompatible with version updates to phone number client versions
# @recorded_by_proxy
# def test_dtmf_actions_in_a_call(self):
# # try to establish the call
# purchased_numbers = list(self.phonenumber_client.list_purchased_phone_numbers())
# if len(purchased_numbers) >= 2:
# caller = PhoneNumberIdentifier(purchased_numbers[0].phone_number)
# target = PhoneNumberIdentifier(purchased_numbers[1].phone_number)
# else:
# raise ValueError("Invalid PSTN setup, test needs at least 2 phone numbers")

# unique_id, call_connection, _ = self.establish_callconnection_pstn(caller, target)

# # check returned events
# connected_event = self.check_for_event('CallConnected', call_connection._call_connection_id, timedelta(seconds=15))
# participant_updated_event = self.check_for_event('ParticipantsUpdated', call_connection._call_connection_id, timedelta(seconds=15))

# if connected_event is None:
# raise ValueError("Caller CallConnected event is None")
# if participant_updated_event is None:
# raise ValueError("Caller ParticipantsUpdated event is None")

# call_connection.start_continuous_dtmf_recognition(target_participant=target)

# # send DTMF tones
# call_connection.send_dtmf_tones(tones=[DtmfTone.POUND], target_participant=target)
# send_dtmf_completed_event = self.check_for_event('SendDtmfTonesCompleted', call_connection._call_connection_id, timedelta(seconds=15),)
# if send_dtmf_completed_event is None:
# raise ValueError("SendDtmfTonesCompleted event is None")

# # stop continuous DTMF recognition
# call_connection.stop_continuous_dtmf_recognition(target_participant=target)
# continuous_dtmf_recognition_stopped_event = self.check_for_event('ContinuousDtmfRecognitionStopped', call_connection._call_connection_id, timedelta(seconds=15))
# if continuous_dtmf_recognition_stopped_event is None:
# raise ValueError("ContinuousDtmfRecognitionStopped event is None")

# self.terminate_call(unique_id)
# return

@pytest.mark.skip(reason="disabling this test due to status code change in the muteparticipant service, current test data doesnt have the change. Created work item to update the test data https://skype.visualstudio.com/SPOOL/_workitems/edit/3602301")
@recorded_by_proxy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Release History

## 1.1.1 (Unreleased)
## 1.2.0b2 (2024-03-01)

### Features Added
- Add support for number lookup
- Format only can be returned for no cost
- Additional number details can be returned for a cost

### Breaking Changes

### Bugs Fixed
## 1.2.0b1 (2023-08-04)

### Other Changes
### Features Added
- Number Lookup API public preview
- API version `2023-05-01-preview` is the default

## 1.1.0 (2023-03-28)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/communication/azure-communication-phonenumbers",
"Tag": "python/communication/azure-communication-phonenumbers_e87531dfe4"
"Tag": "python/communication/azure-communication-phonenumbers_f1965f9584"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
PhoneNumberCountry,
PhoneNumberLocality,
PhoneNumberOffering,
OperatorInformationResult,
)

__all__ = [
Expand All @@ -36,5 +37,6 @@
'PhoneNumberCountry',
'PhoneNumberLocality',
'PhoneNumberOffering',
'OperatorInformationResult',
'PhoneNumbersClient'
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class ApiVersion(str, Enum, metaclass=CaseInsensitiveEnumMeta):
V2022_01_11_PREVIEW2 = "2022-01-11-preview2"
V2022_12_01 = "2022-12-01"
V2023_05_01_PREVIEW = "2023-05-01-preview"
V2024_03_01_PREVIEW = "2024-03-01-preview"


DEFAULT_VERSION = ApiVersion.V2022_12_01
DEFAULT_VERSION = ApiVersion.V2024_03_01_PREVIEW
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any

from azure.core import PipelineClient
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse

from . import models as _models
Expand All @@ -27,8 +28,8 @@ class PhoneNumbersClient: # pylint: disable=client-accepts-api-version-keyword
:param endpoint: The communication resource, for example
https://resourcename.communication.azure.com. Required.
:type endpoint: str
:keyword api_version: Api Version. Default value is "2022-12-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2024-03-01-preview". Note that overriding
this default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
Expand All @@ -39,7 +40,24 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
) -> None:
_endpoint = "{endpoint}"
self._config = PhoneNumbersClientConfiguration(endpoint=endpoint, **kwargs)
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

client_models = {k: v for k, v in _models._models.__dict__.items() if isinstance(v, type)}
client_models.update({k: v for k, v in _models.__dict__.items() if isinstance(v, type)})
Expand All @@ -48,7 +66,7 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self._serialize.client_side_validation = False
self.phone_numbers = PhoneNumbersOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.

>>> from azure.core.rest import HttpRequest
Expand All @@ -72,7 +90,7 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, **kwargs)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
self._client.close()
Expand All @@ -81,5 +99,5 @@ def __enter__(self) -> "PhoneNumbersClient":
self._client.__enter__()
return self

def __exit__(self, *exc_details) -> None:
def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

import sys
from typing import Any

from azure.core.configuration import Configuration
from azure.core.pipeline import policies

if sys.version_info >= (3, 8):
from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports
else:
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports

VERSION = "unknown"


class PhoneNumbersClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
class PhoneNumbersClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
"""Configuration for PhoneNumbersClient.

Note that all parameters used to create this instance are saved as instance
Expand All @@ -29,21 +22,21 @@ class PhoneNumbersClientConfiguration(Configuration): # pylint: disable=too-man
:param endpoint: The communication resource, for example
https://resourcename.communication.azure.com. Required.
:type endpoint: str
:keyword api_version: Api Version. Default value is "2022-12-01". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: Api Version. Default value is "2024-03-01-preview". Note that overriding
this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, **kwargs: Any) -> None:
super(PhoneNumbersClientConfiguration, self).__init__(**kwargs)
api_version: Literal["2022-12-01"] = kwargs.pop("api_version", "2022-12-01")
api_version: str = kwargs.pop("api_version", "2024-03-01-preview")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")

self.endpoint = endpoint
self.api_version = api_version
kwargs.setdefault("sdk_moniker", "phonenumbersclient/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _configure(self, **kwargs: Any) -> None:
Expand All @@ -52,7 +45,7 @@ def _configure(self, **kwargs: Any) -> None:
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
Loading