Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication Administration: Add on-demand resource creation for live-tests #14366

Merged
merged 28 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7f8f8a7
Add communication service preparer
Sep 29, 2020
ac3295b
Refactor dynamic resource creation testing code
Sep 30, 2020
711b983
Remove setup method of base test class
Oct 1, 2020
0a48434
Change fake conn str to valid format
Oct 1, 2020
cb2e0fc
Remove unused import
Oct 1, 2020
64fdead
Remove main test file
Oct 2, 2020
97c029a
Reduce RG expiry durtion
Oct 2, 2020
7f972ae
Async test code change with resource preparer
Oct 2, 2020
aeae711
Add chaching for resource-preparer
Oct 7, 2020
f20059c
Move helper into shared
Oct 7, 2020
1d3bbfd
Move preparer into shared
Oct 7, 2020
3ac4e50
Uncomment test code
Oct 7, 2020
7bd45af
Remove CommunicationResourceGroupPreparer use common instead
Oct 8, 2020
6761bc1
Add base testcase for sync pnm
Oct 8, 2020
6fa98d1
move phone_number_helper to phone_number folder
Oct 8, 2020
31e07bd
Add base pnm async testcase
Oct 8, 2020
e6d6bf7
Add __init__ for test folders
Oct 8, 2020
6dd5d8b
Fix identity tests to refer to shared test folder
Oct 8, 2020
a59ea3f
Refactor base async phonenumber test class
Oct 8, 2020
d84818e
Make decorator consisitent across all async tests utm
Oct 8, 2020
f6f7423
Replace fake resource value
Oct 8, 2020
c4b840d
Fix type in test file names
Oct 8, 2020
b22f986
Remove commented cache setting code
Oct 8, 2020
ae2c176
Add livetest recording files
Oct 8, 2020
52e2873
Refresh recording files
Oct 8, 2020
1956579
Update recording files
Oct 9, 2020
4f8fa09
Reorganize the test folder structure
Oct 12, 2020
09d641c
Add mgmt pacakge to the dev reqs
Oct 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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