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]: Migrated python identity tests to use ARM template #17890

Merged
merged 4 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -3,87 +3,10 @@
# Licensed under the MIT License.
# ------------------------------------

import datetime
import functools
from devtools_testutils import PowerShellPreparer

from azure.mgmt.communication import CommunicationServiceManagementClient
from azure.mgmt.communication.models import CommunicationServiceResource
from devtools_testutils import(
AzureMgmtPreparer,
ResourceGroupPreparer,
FakeResource
CommunicationPreparer = functools.partial(
PowerShellPreparer, "communication",
communication_connection_string="endpoint=https://sanitized.communication.azure.com/;accesskey=fake==="
)
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,
use_cache=False,
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.random_name_enabled = True
self.service_name = "TEST-SERVICE-NAME"
self.mgmt_client = None
self.set_cache(use_cache)
self.scrubbed_resource_name = "communicationegrcrs"

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):
if not self.is_live:
self.resource = FakeResource(name=self.scrubbed_resource_name, id=name)

return {
"connection_string": "endpoint=https://{}.communication.azure.com/;accesskey=fake===".format(self.resource.name),
}

self.test_class_instance.scrubber.register_name_pair(name, self.scrubbed_resource_name)
group_name = self._get_resource_group(**kwargs).name

self.client = self.create_mgmt_client(CommunicationServiceManagementClient, polling_interval=30)

self.resource = self.client.communication_service.begin_create_or_update(
group_name,
name,
CommunicationServiceResource(location="global", data_location="UnitedStates")
).result()

self.service_name = self.resource.name

primary_connection_string = self.client.communication_service.list_keys(
group_name,
self.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.client.communication_service.begin_delete(group_name, self.service_name).wait()
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import re
from azure_devtools.scenario_tests import RecordingProcessor
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse

class URIIdentityReplacer(RecordingProcessor):
"""Replace the identity in request uri"""
def process_request(self, request):
import re
request.uri = re.sub('/identities/([^/?]+)', '/identities/sanitized', request.uri)
resource = (urlparse(request.uri).netloc).split('.')[0]
request.uri = re.sub('/identities/([^/?]+)', '/identities/sanitized', request.uri)
request.uri = re.sub(resource, 'sanitized', request.uri)
return request

def process_response(self, response):
import re
if 'url' in response:
response['url'] = re.sub('/identities/([^/?]+)', '/identities/sanitized', response['url'])
return response
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,33 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 29 Jan 2021 22:48:30 GMT
- Tue, 13 Apr 2021 17:54:24 GMT
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
response:
body:
string: '{"identity": {"id": "sanitized"}}'
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 22:48:29 GMT
- Tue, 13 Apr 2021 17:54:24 GMT
ms-cv:
- 8tfK3/iTvEmwjYUYlPn7Qg.0
- UEGC+xqwQkqRRfXm5Md24A.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 209ms
- 12ms
status:
code: 201
message: Created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,34 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 29 Jan 2021 22:50:21 GMT
- Tue, 13 Apr 2021 17:54:24 GMT
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
response:
body:
string: '{"identity": {"id": "sanitized"}, "accessToken": {"token": "sanitized",
"expiresOn": "2021-01-30T22:50:20.3668737+00:00"}}'
"expiresOn": "2021-04-14T17:54:25.0058231+00:00"}}'
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 22:50:20 GMT
- Tue, 13 Apr 2021 17:54:25 GMT
ms-cv:
- 4wYYchxOnEay3S80a4tugw.0
- I9ZS0qxvQEKYO/S5ErFh1w.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 38ms
- 215ms
status:
code: 201
message: Created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@ interactions:
Content-Type:
- application/json
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
response:
body:
string: '{"identity": {"id": "sanitized"}}'
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 22:21:01 GMT
- Tue, 13 Apr 2021 17:54:27 GMT
ms-cv:
- T/Hx9aJuMka5ZSLjy1uvxA.0
- Z2JdPGt9IEegXVCKKHjiJg.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 247ms
- 162ms
status:
code: 201
message: Created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,33 @@ interactions:
Content-Type:
- application/json
Date:
- Fri, 29 Jan 2021 22:23:15 GMT
- Tue, 13 Apr 2021 17:54:26 GMT
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
x-ms-return-client-request-id:
- 'true'
method: POST
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
response:
body:
string: '{"identity": {"id": "sanitized"}}'
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 22:23:14 GMT
- Tue, 13 Apr 2021 17:54:27 GMT
ms-cv:
- TgHUTqnyBk+TTGrk+qGYCg.0
- NpGxr/VCv0i3/F8p8B/PEw.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 22ms
- 16ms
status:
code: 201
message: Created
Expand All @@ -53,27 +55,29 @@ interactions:
Content-Length:
- '0'
Date:
- Fri, 29 Jan 2021 22:23:15 GMT
- Tue, 13 Apr 2021 17:54:27 GMT
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
x-ms-return-client-request-id:
- 'true'
method: DELETE
uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities/sanitized?api-version=2021-03-07
response:
body:
string: ''
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
date:
- Fri, 29 Jan 2021 22:23:14 GMT
- Tue, 13 Apr 2021 17:54:27 GMT
ms-cv:
- phAKzopa7kCat9napbUQGQ.0
- zRztRbFrrEe9RLXIARPN7w.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
x-processing-time:
- 245ms
- 583ms
status:
code: 204
message: No Content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@ interactions:
Content-Type:
- application/json
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
response:
body:
string: '{"identity": {"id": "sanitized"}}'
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
content-type:
- application/json; charset=utf-8
date:
- Fri, 29 Jan 2021 22:24:21 GMT
- Tue, 13 Apr 2021 17:54:29 GMT
ms-cv:
- 8Dz7rbKlnUyC0X9hMkHkGg.0
- 3qpzL2TAgU2LX4OLE/ZWKQ.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
transfer-encoding:
- chunked
x-processing-time:
- 203ms
- 91ms
status:
code: 201
message: Created
Expand All @@ -49,23 +51,25 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07
uri: https://sanitized.communication.azure.com/identities/sanitized?api-version=2021-03-07
response:
body:
string: ''
headers:
api-supported-versions:
- 2020-07-20-preview2, 2021-03-07
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
date:
- Fri, 29 Jan 2021 22:24:21 GMT
- Tue, 13 Apr 2021 17:54:30 GMT
ms-cv:
- 573z+Dhr+UOuJm8r75diNA.0
- 04FDSY1mSkeU92Los0y+zA.0
request-context:
- appId=
strict-transport-security:
- max-age=2592000
x-processing-time:
- 479ms
- 591ms
status:
code: 204
message: No Content
Expand Down
Loading