|
| 1 | +# ------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for |
| 4 | +# license information. |
| 5 | +# -------------------------------------------------------------------------- |
| 6 | +import pytest |
| 7 | + |
| 8 | +from azure.core.credentials import AzureKeyCredential |
| 9 | +from azure.mixedreality.remoterendering import RemoteRenderingClient |
| 10 | +from azure.mixedreality.remoterendering.aio import RemoteRenderingClient as RemoteRenderingClientAsync |
| 11 | +from devtools_testutils.sanitizers import ( |
| 12 | + add_body_key_sanitizer, |
| 13 | + add_general_regex_sanitizer, |
| 14 | + add_remove_header_sanitizer, |
| 15 | + is_live |
| 16 | +) |
| 17 | + |
| 18 | +# Environment variable keys |
| 19 | +ENV_ARR_SERVICE_ENDPOINT = "REMOTERENDERING_ARR_SERVICE_ENDPOINT" |
| 20 | +ENV_ARR_ACCOUNT_DOMAIN = "REMOTERENDERING_ARR_ACCOUNT_DOMAIN" |
| 21 | +ENV_ARR_ACCOUNT_ID = "REMOTERENDERING_ARR_ACCOUNT_ID" |
| 22 | +ENV_ARR_ACCOUNT_KEY = "REMOTERENDERING_ARR_ACCOUNT_KEY" |
| 23 | +ENV_ARR_STORAGE_ACCOUNT_NAME = "REMOTERENDERING_ARR_STORAGE_ACCOUNT_NAME" |
| 24 | +ENV_ARR_SAS_TOKEN = "REMOTERENDERING_ARR_SAS_TOKEN" |
| 25 | +ENV_ARR_BLOB_CONTAINER_NAME = "REMOTERENDERING_ARR_BLOB_CONTAINER_NAME" |
| 26 | +ENV_STORAGE_ENDPOINT_SUFFIX = "REMOTERENDERING_STORAGE_ENDPOINT_SUFFIX" |
| 27 | + |
| 28 | +# Fake values |
| 29 | +TEST_ARR_SERVICE_ENDPOINT = "https://remoterendering.eastus.mixedreality.azure.com" |
| 30 | +TEST_ARR_ACCOUNT_DOMAIN = "eastus.mixedreality.azure.com" |
| 31 | +TEST_ARR_ACCOUNT_ID = "00000000-0000-0000-0000-000000000000" |
| 32 | +TEST_ARR_ACCOUNT_KEY = "fakekey" |
| 33 | +TEST_ARR_STORAGE_ACCOUNT_NAME = "arrstorageaccount" |
| 34 | +TEST_ARR_SAS_TOKEN = "sv=2015-04-05&sr=c&se=2122-03-10T16%3A13%3A40.0000000Z&sp=rwl&sig=fakeSig" |
| 35 | +TEST_ARR_BLOB_CONTAINER_NAME = "test" |
| 36 | +TEST_STORAGE_ENDPOINT_SUFFIX = "storage_endpoint_suffix" |
| 37 | +TEST_ID_PLACEHOLDER = "rr-test-id" |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture(scope="session", autouse=True) |
| 41 | +def add_sanitizers(test_proxy, environment_variables): |
| 42 | + sanitization_mapping = { |
| 43 | + ENV_ARR_SERVICE_ENDPOINT: TEST_ARR_SERVICE_ENDPOINT, |
| 44 | + ENV_ARR_ACCOUNT_DOMAIN: TEST_ARR_ACCOUNT_DOMAIN, |
| 45 | + ENV_ARR_ACCOUNT_ID: TEST_ARR_ACCOUNT_ID, |
| 46 | + ENV_ARR_ACCOUNT_KEY: TEST_ARR_ACCOUNT_KEY, |
| 47 | + ENV_ARR_STORAGE_ACCOUNT_NAME: TEST_ARR_STORAGE_ACCOUNT_NAME, |
| 48 | + ENV_ARR_SAS_TOKEN: TEST_ARR_SAS_TOKEN, |
| 49 | + ENV_ARR_BLOB_CONTAINER_NAME: TEST_ARR_BLOB_CONTAINER_NAME, |
| 50 | + ENV_STORAGE_ENDPOINT_SUFFIX: TEST_STORAGE_ENDPOINT_SUFFIX |
| 51 | + } |
| 52 | + environment_variables.sanitize_batch(sanitization_mapping) |
| 53 | + add_remove_header_sanitizer(headers="X-MRC-CV") |
| 54 | + add_body_key_sanitizer(json_path="AccessToken", value="fake.eyJleHAiOjIxNDc0ODM2NDd9.fake") |
| 55 | + add_general_regex_sanitizer( |
| 56 | + regex=f"{TEST_ID_PLACEHOLDER}[a-z0-9-]+", |
| 57 | + value=TEST_ID_PLACEHOLDER |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +@pytest.fixture(scope="session") |
| 62 | +def account_info(environment_variables): |
| 63 | + yield { |
| 64 | + "service_endpoint": environment_variables.get(ENV_ARR_SERVICE_ENDPOINT), |
| 65 | + "account_domain": environment_variables.get(ENV_ARR_ACCOUNT_DOMAIN), |
| 66 | + "account_id": environment_variables.get(ENV_ARR_ACCOUNT_ID), |
| 67 | + "account_key": environment_variables.get(ENV_ARR_ACCOUNT_KEY), |
| 68 | + "storage_account_name": environment_variables.get(ENV_ARR_STORAGE_ACCOUNT_NAME), |
| 69 | + "sas_token": environment_variables.get(ENV_ARR_SAS_TOKEN), |
| 70 | + "blob_container_name": environment_variables.get(ENV_ARR_BLOB_CONTAINER_NAME), |
| 71 | + "storage_endpoint_suffix": environment_variables.get(ENV_STORAGE_ENDPOINT_SUFFIX), |
| 72 | + "key_credential": AzureKeyCredential(environment_variables.get(ENV_ARR_ACCOUNT_KEY)), |
| 73 | + "id_placeholder": TEST_ID_PLACEHOLDER |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | +@pytest.fixture |
| 78 | +def arr_client(account_info): |
| 79 | + # Give a small interval for playback tests to avoid |
| 80 | + # a race condition where a poller consumes more recorded requests |
| 81 | + # than expected. |
| 82 | + polling_interval = 10 if is_live() else 0.2 |
| 83 | + client = RemoteRenderingClient( |
| 84 | + endpoint=account_info["service_endpoint"], |
| 85 | + account_id=account_info["account_id"], |
| 86 | + account_domain=account_info["account_domain"], |
| 87 | + credential=account_info["key_credential"], |
| 88 | + polling_interval=polling_interval |
| 89 | + ) |
| 90 | + yield client |
| 91 | + client.close() |
| 92 | + |
| 93 | + |
| 94 | +@pytest.fixture |
| 95 | +async def async_arr_client(account_info): |
| 96 | + polling_interval = 10 if is_live() else 0 |
| 97 | + client = RemoteRenderingClientAsync( |
| 98 | + endpoint=account_info["service_endpoint"], |
| 99 | + account_id=account_info["account_id"], |
| 100 | + account_domain=account_info["account_domain"], |
| 101 | + credential=account_info["key_credential"], |
| 102 | + polling_interval=polling_interval |
| 103 | + ) |
| 104 | + yield client |
| 105 | + await client.close() |
0 commit comments