-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SDK bug. Add UT for CallingServer Client apis.
- Loading branch information
1 parent
a8131d5
commit d15dbca
Showing
13 changed files
with
499 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
sdk/communication/azure-communication-callingserver/tests/_test_constants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
RESOURCE_SOURCE = "8:acs:resource_source" | ||
RESOURCE_TARGET = "8:acs:resource_target" | ||
Phone_Number = "+14255550123" | ||
CALL_ID = "cad9df7b-f3ac-4c53-96f7-c76e7437b3c1" | ||
CALLBACK_URI = "callBackUri" | ||
CONNECTION_STRING = "endpoint=https://REDACTED.communication.azure.com/;accesskey=eyJhbG==" | ||
FAKE_ENDPOINT = "https://endpoint" | ||
FAKE_TOKEN = "Fake Token" | ||
CALL_SUBJECT = "testsubject" | ||
CreateOrJoinCallPayload={ | ||
"callLegId": CALL_ID, | ||
"callConnectionId": CALL_ID, | ||
} | ||
ErrorPayload={"msg": "some error"} | ||
|
||
ClientType_ConnectionString = "use connectionString" | ||
ClientType_ManagedIdentity = "use managedIdentity" | ||
|
||
SEVERCALL_ID = "b3ba87f4-9daf-4d0b-b95a-53d955a40577" |
83 changes: 83 additions & 0 deletions
83
sdk/communication/azure-communication-callingserver/tests/_test_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
import json | ||
import unittest | ||
|
||
import _test_constants | ||
from azure.core.credentials import AccessToken | ||
from azure.communication.callingserver.aio import CallingServerClient as CallingServerClientAsync | ||
from azure.communication.callingserver import CallingServerClient | ||
|
||
try: | ||
from unittest.mock import Mock, patch | ||
except ImportError: # python < 3.3 | ||
from mock import Mock, patch # type: ignore | ||
|
||
class FakeTokenCredential(object): | ||
def __init__(self): | ||
self.token = AccessToken(_test_constants.FAKE_TOKEN, 0) | ||
def get_token(self, *args): | ||
return self.token | ||
|
||
class FakeTokenCredential_Async(object): | ||
def __init__(self): | ||
self.token = AccessToken(_test_constants.FAKE_TOKEN, 0) | ||
async def get_token(self, *args): | ||
return self.token | ||
|
||
def create_mock_call_connection(status_code, payload, is_async=False): | ||
calling_server_client = create_mock_calling_server_client(status_code, payload, is_async) | ||
return calling_server_client.get_call_connection(_test_constants.CALL_ID) | ||
|
||
def create_mock_calling_server_client(status_code, payload, is_async=False, use_managed_identity=False): | ||
async def async_mock_send(*_, **__): | ||
return _mock_response(status_code=status_code, json_payload=payload) | ||
|
||
def mock_send(*_, **__): | ||
return _mock_response(status_code=status_code, json_payload=payload) | ||
|
||
if is_async: | ||
return create_calling_server_client_async(async_mock_send, use_managed_identity) | ||
return create_calling_server_client(mock_send, use_managed_identity) | ||
|
||
def create_calling_server_client_async(mock_transport=None, use_managed_identity=False): | ||
if mock_transport is None: | ||
return ( | ||
CallingServerClientAsync.from_connection_string(_test_constants.CONNECTION_STRING) | ||
if use_managed_identity | ||
else CallingServerClientAsync(_test_constants.FAKE_ENDPOINT, FakeTokenCredential_Async()) | ||
) | ||
|
||
return ( | ||
CallingServerClientAsync.from_connection_string(_test_constants.CONNECTION_STRING, transport=Mock(send=mock_transport)) | ||
if use_managed_identity | ||
else CallingServerClientAsync(_test_constants.FAKE_ENDPOINT, FakeTokenCredential_Async(), transport=Mock(send=mock_transport)) | ||
) | ||
|
||
def create_calling_server_client(mock_transport=None, use_managed_identity=False): | ||
if mock_transport is None: | ||
return ( | ||
CallingServerClient.from_connection_string(_test_constants.CONNECTION_STRING) | ||
if use_managed_identity | ||
else CallingServerClient(_test_constants.FAKE_ENDPOINT, FakeTokenCredential()) | ||
) | ||
return ( | ||
CallingServerClient.from_connection_string(_test_constants.CONNECTION_STRING, transport=Mock(send=mock_transport)) | ||
if use_managed_identity | ||
else CallingServerClient(_test_constants.FAKE_ENDPOINT, FakeTokenCredential(), transport=Mock(send=mock_transport)) | ||
) | ||
|
||
def _mock_response(status_code=200, headers=None, json_payload=None): | ||
response = Mock(status_code=status_code, headers=headers or {}) | ||
if json_payload is not None: | ||
response.text = lambda encoding=None: json.dumps(json_payload) | ||
response.headers["content-type"] = "application/json" | ||
response.content_type = "application/json" | ||
else: | ||
response.text = lambda encoding=None: "" | ||
response.headers["content-type"] = "text/plain" | ||
response.content_type = "text/plain" | ||
return response |
11 changes: 11 additions & 0 deletions
11
sdk/communication/azure-communication-callingserver/tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
import sys | ||
|
||
# Ignore collection of async tests for Python 2 | ||
collect_ignore_glob = [] | ||
if sys.version_info < (3, 5): | ||
collect_ignore_glob.append("*_async.py") |
Empty file.
Empty file.
Oops, something went wrong.