-
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.
Communication Administration: Add on-demand resource creation for liv…
…e-tests (#14366) * Add communication service preparer * Refactor dynamic resource creation testing code * Remove setup method of base test class * Change fake conn str to valid format * Remove unused import * Remove main test file * Reduce RG expiry durtion * Async test code change with resource preparer * Add chaching for resource-preparer * Move helper into shared * Move preparer into shared * Uncomment test code * Remove CommunicationResourceGroupPreparer use common instead * Add base testcase for sync pnm * move phone_number_helper to phone_number folder * Add base pnm async testcase * Add __init__ for test folders * Fix identity tests to refer to shared test folder * Refactor base async phonenumber test class * Make decorator consisitent across all async tests utm * Replace fake resource value * Fix type in test file names * Remove commented cache setting code * Add livetest recording files * Refresh recording files * Update recording files * Reorganize the test folder structure * Add mgmt pacakge to the dev reqs Co-authored-by: tural farhadov <tufarhad@microsoft.com>
- Loading branch information
Showing
55 changed files
with
633 additions
and
966 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
78 changes: 78 additions & 0 deletions
78
...cation/azure-communication-administration/tests/_shared/communication_service_preparer.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,78 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
import datetime | ||
|
||
from azure.mgmt.communication import CommunicationServiceManagementClient | ||
from azure.mgmt.communication.models import CommunicationServiceResource | ||
from devtools_testutils import AzureMgmtPreparer, ResourceGroupPreparer | ||
from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM | ||
from azure_devtools.scenario_tests.exceptions import AzureTestError | ||
|
||
class CommunicationServicePreparer(AzureMgmtPreparer): | ||
"""Communication Service Preparer. | ||
Creating and destroying test resources on demand | ||
""" | ||
def __init__( | ||
self, | ||
name_prefix="communication", | ||
resource_group_parameter_name=RESOURCE_GROUP_PARAM, | ||
disable_recording=True, | ||
playback_fake_resource=None, | ||
client_kwargs=None, | ||
): | ||
super(CommunicationServicePreparer, self).__init__( | ||
name_prefix, | ||
random_name_length=24, | ||
disable_recording=disable_recording, | ||
playback_fake_resource=playback_fake_resource, | ||
client_kwargs=client_kwargs, | ||
) | ||
self.resource_group_parameter_name = resource_group_parameter_name | ||
self.service_name = "TEST-SERVICE-NAME" | ||
self.mgmt_client = None | ||
|
||
def _get_resource_group(self, **kwargs): | ||
try: | ||
return kwargs[self.resource_group_parameter_name] | ||
except KeyError: | ||
template = ( | ||
"To create a communication service a resource group is required. Please add " | ||
"decorator @{} in front of this preparer." | ||
) | ||
raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) | ||
|
||
def create_resource(self, name, **kwargs): | ||
self.service_name = self.create_random_name() | ||
|
||
if not self.is_live: | ||
return { | ||
"connection_string": "endpoint=https://fake-resource.communication.azure.com/;accesskey=fake===", | ||
} | ||
|
||
group_name = self._get_resource_group(**kwargs).name | ||
|
||
self.mgmt_client = self.create_mgmt_client(CommunicationServiceManagementClient) | ||
|
||
resource = self.mgmt_client.communication_service.begin_create_or_update( | ||
group_name, | ||
self.service_name, | ||
CommunicationServiceResource(location="global", data_location="UnitedStates") | ||
).result() | ||
|
||
primary_connection_string = self.mgmt_client.communication_service.list_keys( | ||
group_name, | ||
resource.name).primary_connection_string | ||
|
||
return { | ||
"connection_string": primary_connection_string, | ||
} | ||
|
||
def remove_resource(self, name, **kwargs): | ||
if not self.is_live: | ||
return | ||
|
||
group_name = self._get_resource_group(**kwargs).name | ||
self.mgmt_client.communication_service.begin_delete(group_name, self.service_name).wait() |
File renamed without changes.
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
20 changes: 20 additions & 0 deletions
20
sdk/communication/azure-communication-administration/tests/phone_number_testcase.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,20 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
import os | ||
from azure.communication.administration._shared.utils import parse_connection_str | ||
from _shared.testcase import CommunicationTestCase | ||
|
||
class PhoneNumberCommunicationTestCase(CommunicationTestCase): | ||
def setUp(self): | ||
super(PhoneNumberCommunicationTestCase, self).setUp() | ||
|
||
if self.is_playback(): | ||
self.connection_str = "endpoint=https://sanitized/;accesskey=fake===" | ||
else: | ||
self.connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') | ||
endpoint, _ = parse_connection_str(self.connection_str) | ||
self._resource_name = endpoint.split(".")[0] | ||
self.scrubber.register_name_pair(self._resource_name, "sanitized") |
13 changes: 13 additions & 0 deletions
13
sdk/communication/azure-communication-administration/tests/phone_number_testcase_async.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,13 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
import os | ||
from azure.communication.administration._shared.utils import parse_connection_str | ||
from phone_number_testcase import PhoneNumberCommunicationTestCase | ||
from _shared.asynctestcase import AsyncCommunicationTestCase | ||
|
||
class AsyncPhoneNumberCommunicationTestCase(PhoneNumberCommunicationTestCase, AsyncCommunicationTestCase): | ||
def setUp(self): | ||
super(AsyncPhoneNumberCommunicationTestCase, self).setUp() |
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
Oops, something went wrong.