Skip to content

Commit

Permalink
[Communication]Migrate ACS Rooms Python to use new Test Proxy (#30217)
Browse files Browse the repository at this point in the history
* Migrate ACS Rooms Python to use new Test Proxy

* santizie MS-CV and other response headers

* Address comments

* Fix tests in playback mode

* Fix tests in playback mode

* Refactor

---------

Co-authored-by: Minnie Liu <[email protected]>
  • Loading branch information
minnieliu and Minnie Liu authored May 6, 2023
1 parent fbb7a4a commit cbb3590
Show file tree
Hide file tree
Showing 79 changed files with 3,859 additions and 14,527 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-e ../azure-communication-identity
../../core/azure-core
../../identity/azure-identity
aiohttp>=3.0;
aiohttp>=3.0
typing_extensions>=3.7.2
aiounittest>=1.4
asyncio
asyncio
3 changes: 3 additions & 0 deletions sdk/communication/azure-communication-rooms/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ stages:
Clouds: Public,Int
TestResourceDirectories:
- communication/test-resources/
EnvVars:
AZURE_SKIP_LIVE_RECORDING: 'True'
AZURE_TEST_RUN_LIVE: 'true'

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding: utf-8
# -------------------------------------------------------------------------
# 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 devtools_testutils import AzureRecordedTestCase, is_live
from azure.communication.rooms._shared.utils import parse_connection_str

class ACSRoomsTestCase(AzureRecordedTestCase):
def setUp(self):
if is_live():
self.connection_str = os.getenv('COMMUNICATION_CONNECTION_STRING_ROOMS')
self.endpoint, _ = parse_connection_str(self.connection_str)
self._resource_name = self.endpoint.split(".")[0]
else:
self.connection_str = "endpoint=https://sanitized.communication.azure.com/;accesskey=fake==="
self.endpoint, _ = parse_connection_str(self.connection_str)
self._resource_name = self.endpoint.split(".")[0]

54 changes: 54 additions & 0 deletions sdk/communication/azure-communication-rooms/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# --------------------------------------------------------------------------
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the ""Software""), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import pytest
import os
from devtools_testutils import add_general_string_sanitizer, add_header_regex_sanitizer, add_body_key_sanitizer, set_default_session_settings
from azure.communication.rooms._shared.utils import parse_connection_str

@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
set_default_session_settings()

communication_connection_string = os.getenv("COMMUNICATION_CONNECTION_STRING_ROOMS", "endpoint=https://sanitized.communication.azure.com/;accesskey=fake===")

add_general_string_sanitizer(target=communication_connection_string, value="endpoint=https://sanitized.communication.azure.com/;accesskey=fake===")
endpoint, _ = parse_connection_str(communication_connection_string)
add_general_string_sanitizer(target=endpoint, value="sanitized.communication.azure.com")
add_header_regex_sanitizer(key="x-ms-content-sha256", value="sanitized")
add_header_regex_sanitizer(key="Set-Cookie", value="sanitized")
add_header_regex_sanitizer(key="Date", value="sanitized")
add_header_regex_sanitizer(key="Cookie", value="sanitized")
add_header_regex_sanitizer(key="client-request-id", value="sanitized")
add_header_regex_sanitizer(key="MS-CV", value="sanitized")
add_header_regex_sanitizer(key="X-Azure-Ref", value="sanitized")
add_header_regex_sanitizer(key="x-ms-content-sha256", value="sanitized")
add_header_regex_sanitizer(key="x-ms-client-request-id", value="sanitized")
add_header_regex_sanitizer(key="x-ms-date", value="sanitized")
add_header_regex_sanitizer(key="x-ms-request-id", value="sanitized")
add_header_regex_sanitizer(
key="Content-Security-Policy-Report-Only", value="sanitized")
add_header_regex_sanitizer(key="Repeatability-First-Sent", value="sanitized")
add_header_regex_sanitizer(key="Repeatability-Request-ID", value="sanitized")
20 changes: 0 additions & 20 deletions sdk/communication/azure-communication-rooms/tests/helper.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"Entries": [
{
"RequestUri": "https://sanitized.communication.azure.com/rooms?api-version=2023-03-31-preview",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Authorization": "Sanitized",
"Connection": "keep-alive",
"Content-Length": "142",
"Content-Type": "application/json",
"Repeatability-First-Sent": "sanitized",
"Repeatability-Request-ID": "sanitized",
"User-Agent": "azsdk-python-communication-rooms/1.0.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-client-request-id": "sanitized",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": {
"validFrom": null,
"validUntil": null,
"participants": {
"8:acs:sanitized1": {
"role": "Presenter"
},
"8:acs:sanitized3": {
"role": "Attendee"
}
}
},
"StatusCode": 201,
"ResponseHeaders": {
"api-deprecated-versions": "2021-04-07",
"api-supported-versions": "2022-02-01, 2023-03-31-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"Location": "99438909571195444",
"MS-CV": "sanitized",
"Repeatability-Result": "accepted",
"Request-Context": "appId=",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE"
},
"ResponseBody": {
"id": "99438909571195444",
"createdAt": "2023-05-05T21:09:08.8167074\u002B00:00",
"validFrom": "2023-05-05T21:09:08.7637676\u002B00:00",
"validUntil": "2023-11-01T21:09:08.7637676\u002B00:00"
}
},
{
"RequestUri": "https://sanitized.communication.azure.com/rooms/99438909571195444/participants?api-version=2023-03-31-preview",
"RequestMethod": "PATCH",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Authorization": "Sanitized",
"Connection": "keep-alive",
"Content-Length": "102",
"Content-Type": "application/merge-patch\u002Bjson",
"User-Agent": "azsdk-python-communication-rooms/1.0.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-client-request-id": "sanitized",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": {
"participants": {
"8:acs:sanitized1": {
"role": "Consumer"
},
"8:acs:sanitized2": {
"role": "Consumer"
}
}
},
"StatusCode": 200,
"ResponseHeaders": {
"api-supported-versions": "2022-02-01, 2023-03-31-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"MS-CV": "sanitized",
"Request-Context": "appId=",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE"
},
"ResponseBody": {}
},
{
"RequestUri": "https://sanitized.communication.azure.com/rooms/99438909571195444/participants?api-version=2023-03-31-preview",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Authorization": "Sanitized",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-communication-rooms/1.0.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-client-request-id": "sanitized",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"api-supported-versions": "2022-02-01, 2023-03-31-preview",
"Content-Type": "application/json; charset=utf-8",
"Date": "sanitized",
"MS-CV": "sanitized",
"Request-Context": "appId=",
"Transfer-Encoding": "chunked",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE"
},
"ResponseBody": {
"value": [
{
"rawId": "8:acs:sanitized1",
"role": "Consumer"
},
{
"rawId": "8:acs:sanitized3",
"role": "Attendee"
},
{
"rawId": "8:acs:sanitized2",
"role": "Consumer"
}
]
}
},
{
"RequestUri": "https://sanitized.communication.azure.com/rooms/99438909571195444?api-version=2023-03-31-preview",
"RequestMethod": "DELETE",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Authorization": "Sanitized",
"Connection": "keep-alive",
"Content-Length": "0",
"User-Agent": "azsdk-python-communication-rooms/1.0.0b3 Python/3.10.0 (Windows-10-10.0.22621-SP0)",
"x-ms-client-request-id": "sanitized",
"x-ms-content-sha256": "sanitized",
"x-ms-date": "sanitized",
"x-ms-return-client-request-id": "true"
},
"RequestBody": null,
"StatusCode": 204,
"ResponseHeaders": {
"api-deprecated-versions": "2021-04-07",
"api-supported-versions": "2022-02-01, 2023-03-31-preview",
"Date": "sanitized",
"MS-CV": "sanitized",
"Request-Context": "appId=",
"X-Azure-Ref": "sanitized",
"X-Cache": "CONFIG_NOCACHE"
},
"ResponseBody": null
}
],
"Variables": {}
}
Loading

0 comments on commit cbb3590

Please sign in to comment.