Skip to content

Commit

Permalink
Communication Administration: Add on-demand resource creation for liv…
Browse files Browse the repository at this point in the history
…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
turalf and tural farhadov authored Oct 13, 2020
1 parent bc8939e commit e261627
Show file tree
Hide file tree
Showing 55 changed files with 633 additions and 966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
-e ../../../tools/azure-devtools
../../core/azure-core
../azure-communication-nspkg
../azure-mgmt-communication
aiohttp>=3.0; python_version >= '3.5'
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()
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import os
import re
from devtools_testutils import AzureTestCase
from azure.communication.administration._shared.utils import parse_connection_str
from azure_devtools.scenario_tests import RecordingProcessor, ReplayableTest
from azure_devtools.scenario_tests.utilities import is_text_payload

Expand Down Expand Up @@ -68,15 +66,4 @@ class CommunicationTestCase(AzureTestCase):
FILTER_HEADERS = ReplayableTest.FILTER_HEADERS + ['x-azure-ref', 'x-ms-content-sha256', 'location']

def __init__(self, method_name, *args, **kwargs):
super(CommunicationTestCase, self).__init__(method_name, *args, **kwargs)

def setUp(self):
super(CommunicationTestCase, 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")
super(CommunicationTestCase, self).__init__(method_name, *args, **kwargs)
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")
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()
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ interactions:
Content-Length:
- '0'
Date:
- Tue, 29 Sep 2020 17:47:50 GMT
- Sat, 10 Oct 2020 02:12:50 GMT
User-Agent:
- azsdk-python-communication-administration/1.0.0b1 Python/3.8.3 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Linux-5.4.0-48-generic-x86_64-with-glibc2.29)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://sanitized.communication.azure.com/identities?api-version=2020-07-20-preview2
uri: https://communication27b5151c.communication.azure.com/identities?api-version=2020-07-20-preview2
response:
body: '{"id": "sanitized"}'
headers:
Expand All @@ -26,15 +26,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 29 Sep 2020 17:47:50 GMT
- Sat, 10 Oct 2020 02:12:50 GMT
ms-cv:
- CoE2LmTaiE+T/aECFj99Zg.0
- QLKE+FLVdUq7AXq6kOHFAA.0
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 16ms
- 31ms
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ interactions:
Content-Length:
- '0'
Date:
- Tue, 29 Sep 2020 17:47:50 GMT
- Sat, 10 Oct 2020 02:13:54 GMT
User-Agent:
- azsdk-python-communication-administration/1.0.0b1 Python/3.8.3 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Linux-5.4.0-48-generic-x86_64-with-glibc2.29)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://sanitized.communication.azure.com/identities?api-version=2020-07-20-preview2
uri: https://communication279d151b.communication.azure.com/identities?api-version=2020-07-20-preview2
response:
body: '{"id": "sanitized"}'
headers:
Expand All @@ -26,15 +26,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 29 Sep 2020 17:47:50 GMT
- Sat, 10 Oct 2020 02:13:54 GMT
ms-cv:
- FCvz8qTbwEuo51Sfsgj8Hg.0
- 1trS7q04w0Ku0dWvPBHBvg.0
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 16ms
- 61ms
status:
code: 200
message: OK
Expand All @@ -50,27 +50,27 @@ interactions:
Content-Length:
- '0'
Date:
- Tue, 29 Sep 2020 17:47:51 GMT
- Sat, 10 Oct 2020 02:13:54 GMT
User-Agent:
- azsdk-python-communication-administration/1.0.0b1 Python/3.8.3 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Linux-5.4.0-48-generic-x86_64-with-glibc2.29)
x-ms-return-client-request-id:
- 'true'
method: DELETE
uri: https://sanitized.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2
uri: https://communication279d151b.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2
response:
body:
string: ''
headers:
api-supported-versions:
- 2020-07-20-preview1, 2020-07-20-preview2
date:
- Tue, 29 Sep 2020 17:47:51 GMT
- Sat, 10 Oct 2020 02:13:55 GMT
ms-cv:
- /Xzcq087nEObSeLTbe71Lw.0
- HURY7bvoM0qfD9WxGE7Xfg.0
strict-transport-security:
- max-age=2592000
x-processing-time:
- 842ms
- 751ms
status:
code: 204
message: No Content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ interactions:
Content-Length:
- '0'
Date:
- Tue, 29 Sep 2020 17:47:51 GMT
- Sat, 10 Oct 2020 02:14:59 GMT
User-Agent:
- azsdk-python-communication-administration/1.0.0b1 Python/3.8.3 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Linux-5.4.0-48-generic-x86_64-with-glibc2.29)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://sanitized.communication.azure.com/identities?api-version=2020-07-20-preview2
uri: https://communication28c71533.communication.azure.com/identities?api-version=2020-07-20-preview2
response:
body: '{"id": "sanitized"}'
headers:
Expand All @@ -26,15 +26,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 29 Sep 2020 17:47:51 GMT
- Sat, 10 Oct 2020 02:14:59 GMT
ms-cv:
- yRWeRDZM3kG7EUXuSU6PRg.0
- Pww8CtkKzUeaJne5eGvDBA.0
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 16ms
- 33ms
status:
code: 200
message: OK
Expand All @@ -52,30 +52,30 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 29 Sep 2020 17:47:52 GMT
- Sat, 10 Oct 2020 02:14:59 GMT
User-Agent:
- azsdk-python-communication-administration/1.0.0b1 Python/3.8.3 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-administration/1.0.0b2 Python/3.8.5 (Linux-5.4.0-48-generic-x86_64-with-glibc2.29)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://sanitized.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2
uri: https://communication28c71533.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2
response:
body: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-09-30T17:47:51.1213055+00:00"}'
body: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-10-11T02:14:58.7723626+00:00"}'
headers:
api-supported-versions:
- 2020-07-20-preview1, 2020-07-20-preview2
content-type:
- application/json; charset=utf-8
date:
- Tue, 29 Sep 2020 17:47:51 GMT
- Sat, 10 Oct 2020 02:14:59 GMT
ms-cv:
- dd0lZwCvoE6n7W5SIYKdKQ.0
- F0sn/mygTU+RwCNm6UCPGg.0
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 29ms
- 89ms
status:
code: 200
message: OK
Expand Down
Loading

0 comments on commit e261627

Please sign in to comment.