Skip to content

Commit 1b33479

Browse files
[Communication]: Migrated python identity tests to use ARM template (Azure#17890)
* Migrated python identity tests to use ARM template * Update sanitation for the request * Renamed variable in URIIdentityReplacer * Fixed python 2 import error
1 parent 01c8b28 commit 1b33479

File tree

24 files changed

+424
-411
lines changed

24 files changed

+424
-411
lines changed

sdk/communication/azure-communication-identity/tests/_shared/communication_service_preparer.py

Lines changed: 5 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,10 @@
33
# Licensed under the MIT License.
44
# ------------------------------------
55

6-
import datetime
6+
import functools
7+
from devtools_testutils import PowerShellPreparer
78

8-
from azure.mgmt.communication import CommunicationServiceManagementClient
9-
from azure.mgmt.communication.models import CommunicationServiceResource
10-
from devtools_testutils import(
11-
AzureMgmtPreparer,
12-
ResourceGroupPreparer,
13-
FakeResource
9+
CommunicationPreparer = functools.partial(
10+
PowerShellPreparer, "communication",
11+
communication_connection_string="endpoint=https://sanitized.communication.azure.com/;accesskey=fake==="
1412
)
15-
from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM
16-
from azure_devtools.scenario_tests.exceptions import AzureTestError
17-
18-
class CommunicationServicePreparer(AzureMgmtPreparer):
19-
"""Communication Service Preparer.
20-
Creating and destroying test resources on demand
21-
"""
22-
def __init__(
23-
self,
24-
name_prefix="communication",
25-
resource_group_parameter_name=RESOURCE_GROUP_PARAM,
26-
disable_recording=True,
27-
use_cache=False,
28-
playback_fake_resource=None,
29-
client_kwargs=None,
30-
):
31-
super(CommunicationServicePreparer, self).__init__(
32-
name_prefix,
33-
random_name_length=24,
34-
disable_recording=disable_recording,
35-
playback_fake_resource=playback_fake_resource,
36-
client_kwargs=client_kwargs,
37-
)
38-
self.resource_group_parameter_name = resource_group_parameter_name
39-
self.random_name_enabled = True
40-
self.service_name = "TEST-SERVICE-NAME"
41-
self.mgmt_client = None
42-
self.set_cache(use_cache)
43-
self.scrubbed_resource_name = "communicationegrcrs"
44-
45-
def _get_resource_group(self, **kwargs):
46-
try:
47-
return kwargs[self.resource_group_parameter_name]
48-
except KeyError:
49-
template = (
50-
"To create a communication service a resource group is required. Please add "
51-
"decorator @{} in front of this preparer."
52-
)
53-
raise AzureTestError(template.format(ResourceGroupPreparer.__name__))
54-
55-
def create_resource(self, name, **kwargs):
56-
if not self.is_live:
57-
self.resource = FakeResource(name=self.scrubbed_resource_name, id=name)
58-
59-
return {
60-
"connection_string": "endpoint=https://{}.communication.azure.com/;accesskey=fake===".format(self.resource.name),
61-
}
62-
63-
self.test_class_instance.scrubber.register_name_pair(name, self.scrubbed_resource_name)
64-
group_name = self._get_resource_group(**kwargs).name
65-
66-
self.client = self.create_mgmt_client(CommunicationServiceManagementClient, polling_interval=30)
67-
68-
self.resource = self.client.communication_service.begin_create_or_update(
69-
group_name,
70-
name,
71-
CommunicationServiceResource(location="global", data_location="UnitedStates")
72-
).result()
73-
74-
self.service_name = self.resource.name
75-
76-
primary_connection_string = self.client.communication_service.list_keys(
77-
group_name,
78-
self.resource.name).primary_connection_string
79-
80-
return {
81-
"connection_string": primary_connection_string,
82-
}
83-
84-
def remove_resource(self, name, **kwargs):
85-
if not self.is_live:
86-
return
87-
88-
group_name = self._get_resource_group(**kwargs).name
89-
self.client.communication_service.begin_delete(group_name, self.service_name).wait()

sdk/communication/azure-communication-identity/tests/_shared/helper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6+
import re
67
from azure_devtools.scenario_tests import RecordingProcessor
8+
try:
9+
from urllib.parse import urlparse
10+
except ImportError:
11+
from urlparse import urlparse
712

813
class URIIdentityReplacer(RecordingProcessor):
914
"""Replace the identity in request uri"""
1015
def process_request(self, request):
11-
import re
12-
request.uri = re.sub('/identities/([^/?]+)', '/identities/sanitized', request.uri)
16+
resource = (urlparse(request.uri).netloc).split('.')[0]
17+
request.uri = re.sub('/identities/([^/?]+)', '/identities/sanitized', request.uri)
18+
request.uri = re.sub(resource, 'sanitized', request.uri)
1319
return request
1420

1521
def process_response(self, response):
16-
import re
1722
if 'url' in response:
1823
response['url'] = re.sub('/identities/([^/?]+)', '/identities/sanitized', response['url'])
1924
return response

sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,33 @@ interactions:
1313
Content-Type:
1414
- application/json
1515
Date:
16-
- Fri, 29 Jan 2021 22:48:30 GMT
16+
- Tue, 13 Apr 2021 17:54:24 GMT
1717
User-Agent:
18-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
18+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
1919
x-ms-return-client-request-id:
2020
- 'true'
2121
method: POST
22-
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
22+
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
2323
response:
2424
body:
2525
string: '{"identity": {"id": "sanitized"}}'
2626
headers:
2727
api-supported-versions:
28-
- 2020-07-20-preview2, 2021-03-07
28+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
2929
content-type:
3030
- application/json; charset=utf-8
3131
date:
32-
- Fri, 29 Jan 2021 22:48:29 GMT
32+
- Tue, 13 Apr 2021 17:54:24 GMT
3333
ms-cv:
34-
- 8tfK3/iTvEmwjYUYlPn7Qg.0
34+
- UEGC+xqwQkqRRfXm5Md24A.0
35+
request-context:
36+
- appId=
3537
strict-transport-security:
3638
- max-age=2592000
3739
transfer-encoding:
3840
- chunked
3941
x-processing-time:
40-
- 209ms
42+
- 12ms
4143
status:
4244
code: 201
4345
message: Created

sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user_and_token.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,34 @@ interactions:
1313
Content-Type:
1414
- application/json
1515
Date:
16-
- Fri, 29 Jan 2021 22:50:21 GMT
16+
- Tue, 13 Apr 2021 17:54:24 GMT
1717
User-Agent:
18-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
18+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
1919
x-ms-return-client-request-id:
2020
- 'true'
2121
method: POST
22-
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
22+
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
2323
response:
2424
body:
2525
string: '{"identity": {"id": "sanitized"}, "accessToken": {"token": "sanitized",
26-
"expiresOn": "2021-01-30T22:50:20.3668737+00:00"}}'
26+
"expiresOn": "2021-04-14T17:54:25.0058231+00:00"}}'
2727
headers:
2828
api-supported-versions:
29-
- 2020-07-20-preview2, 2021-03-07
29+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
3030
content-type:
3131
- application/json; charset=utf-8
3232
date:
33-
- Fri, 29 Jan 2021 22:50:20 GMT
33+
- Tue, 13 Apr 2021 17:54:25 GMT
3434
ms-cv:
35-
- 4wYYchxOnEay3S80a4tugw.0
35+
- I9ZS0qxvQEKYO/S5ErFh1w.0
36+
request-context:
37+
- appId=
3638
strict-transport-security:
3739
- max-age=2592000
3840
transfer-encoding:
3941
- chunked
4042
x-processing-time:
41-
- 38ms
43+
- 215ms
4244
status:
4345
code: 201
4446
message: Created

sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@ interactions:
1313
Content-Type:
1414
- application/json
1515
User-Agent:
16-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
16+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
1717
method: POST
18-
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
18+
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
1919
response:
2020
body:
2121
string: '{"identity": {"id": "sanitized"}}'
2222
headers:
2323
api-supported-versions:
24-
- 2020-07-20-preview2, 2021-03-07
24+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
2525
content-type:
2626
- application/json; charset=utf-8
2727
date:
28-
- Fri, 29 Jan 2021 22:21:01 GMT
28+
- Tue, 13 Apr 2021 17:54:27 GMT
2929
ms-cv:
30-
- T/Hx9aJuMka5ZSLjy1uvxA.0
30+
- Z2JdPGt9IEegXVCKKHjiJg.0
31+
request-context:
32+
- appId=
3133
strict-transport-security:
3234
- max-age=2592000
3335
transfer-encoding:
3436
- chunked
3537
x-processing-time:
36-
- 247ms
38+
- 162ms
3739
status:
3840
code: 201
3941
message: Created

sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user.yaml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,33 @@ interactions:
1313
Content-Type:
1414
- application/json
1515
Date:
16-
- Fri, 29 Jan 2021 22:23:15 GMT
16+
- Tue, 13 Apr 2021 17:54:26 GMT
1717
User-Agent:
18-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
18+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
1919
x-ms-return-client-request-id:
2020
- 'true'
2121
method: POST
22-
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
22+
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
2323
response:
2424
body:
2525
string: '{"identity": {"id": "sanitized"}}'
2626
headers:
2727
api-supported-versions:
28-
- 2020-07-20-preview2, 2021-03-07
28+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
2929
content-type:
3030
- application/json; charset=utf-8
3131
date:
32-
- Fri, 29 Jan 2021 22:23:14 GMT
32+
- Tue, 13 Apr 2021 17:54:27 GMT
3333
ms-cv:
34-
- TgHUTqnyBk+TTGrk+qGYCg.0
34+
- NpGxr/VCv0i3/F8p8B/PEw.0
35+
request-context:
36+
- appId=
3537
strict-transport-security:
3638
- max-age=2592000
3739
transfer-encoding:
3840
- chunked
3941
x-processing-time:
40-
- 22ms
42+
- 16ms
4143
status:
4244
code: 201
4345
message: Created
@@ -53,27 +55,29 @@ interactions:
5355
Content-Length:
5456
- '0'
5557
Date:
56-
- Fri, 29 Jan 2021 22:23:15 GMT
58+
- Tue, 13 Apr 2021 17:54:27 GMT
5759
User-Agent:
58-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
60+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
5961
x-ms-return-client-request-id:
6062
- 'true'
6163
method: DELETE
62-
uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07
64+
uri: https://sanitized.communication.azure.com/identities/sanitized?api-version=2021-03-07
6365
response:
6466
body:
6567
string: ''
6668
headers:
6769
api-supported-versions:
68-
- 2020-07-20-preview2, 2021-03-07
70+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
6971
date:
70-
- Fri, 29 Jan 2021 22:23:14 GMT
72+
- Tue, 13 Apr 2021 17:54:27 GMT
7173
ms-cv:
72-
- phAKzopa7kCat9napbUQGQ.0
74+
- zRztRbFrrEe9RLXIARPN7w.0
75+
request-context:
76+
- appId=
7377
strict-transport-security:
7478
- max-age=2592000
7579
x-processing-time:
76-
- 245ms
80+
- 583ms
7781
status:
7882
code: 204
7983
message: No Content

sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@ interactions:
1313
Content-Type:
1414
- application/json
1515
User-Agent:
16-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
16+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
1717
method: POST
18-
uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07
18+
uri: https://sanitized.communication.azure.com/identities?api-version=2021-03-07
1919
response:
2020
body:
2121
string: '{"identity": {"id": "sanitized"}}'
2222
headers:
2323
api-supported-versions:
24-
- 2020-07-20-preview2, 2021-03-07
24+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
2525
content-type:
2626
- application/json; charset=utf-8
2727
date:
28-
- Fri, 29 Jan 2021 22:24:21 GMT
28+
- Tue, 13 Apr 2021 17:54:29 GMT
2929
ms-cv:
30-
- 8Dz7rbKlnUyC0X9hMkHkGg.0
30+
- 3qpzL2TAgU2LX4OLE/ZWKQ.0
31+
request-context:
32+
- appId=
3133
strict-transport-security:
3234
- max-age=2592000
3335
transfer-encoding:
3436
- chunked
3537
x-processing-time:
36-
- 203ms
38+
- 91ms
3739
status:
3840
code: 201
3941
message: Created
@@ -49,23 +51,25 @@ interactions:
4951
Content-Length:
5052
- '0'
5153
User-Agent:
52-
- azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0)
54+
- azsdk-python-communication-identity/1.0.0 Python/3.9.0 (Windows-10-10.0.19041-SP0)
5355
method: DELETE
54-
uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07
56+
uri: https://sanitized.communication.azure.com/identities/sanitized?api-version=2021-03-07
5557
response:
5658
body:
5759
string: ''
5860
headers:
5961
api-supported-versions:
60-
- 2020-07-20-preview2, 2021-03-07
62+
- 2020-07-20-preview2, 2021-02-22-preview1, 2021-03-07
6163
date:
62-
- Fri, 29 Jan 2021 22:24:21 GMT
64+
- Tue, 13 Apr 2021 17:54:30 GMT
6365
ms-cv:
64-
- 573z+Dhr+UOuJm8r75diNA.0
66+
- 04FDSY1mSkeU92Los0y+zA.0
67+
request-context:
68+
- appId=
6569
strict-transport-security:
6670
- max-age=2592000
6771
x-processing-time:
68-
- 479ms
72+
- 591ms
6973
status:
7074
code: 204
7175
message: No Content

0 commit comments

Comments
 (0)