Skip to content

Commit b238b8b

Browse files
authored
Use batch sanitizing feature from sanitizing fixture (#36512)
1 parent 35753d3 commit b238b8b

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

sdk/ml/azure-ai-ml/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ml/azure-ai-ml",
5-
"Tag": "python/ml/azure-ai-ml_b0ebee3471"
5+
"Tag": "python/ml/azure-ai-ml_a4bd12953c"
66
}

sdk/ml/azure-ai-ml/tests/component/e2etests/test_component.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ def test_parallel_component(self, client: MLClient, randstr: Callable[[str], str
206206
recorded_component_name="component_name",
207207
)
208208

209-
@pytest.mark.live_test_only("Needs re-recording to work with new test proxy sanitizers")
210209
def test_automl_component(self, client: MLClient, registry_client: MLClient, randstr: Callable[[str], str]) -> None:
211210
expected_component_dict = {
212211
"description": "Component that executes an AutoML Classification task model training in a pipeline.",

sdk/ml/azure-ai-ml/tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ def add_sanitizers(test_proxy, fake_datastore_key):
133133

134134
# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
135135
# - AZSDK3430: $..id
136+
# - AZSDK3436: $..resourceGroup
136137
# - AZSDK3493: $..name
137138
# - AZSDK2003: Location
138-
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493", "AZSDK2003"])
139+
remove_batch_sanitizers(["AZSDK3430", "AZSDK3493", "AZSDK2003", "AZSDK3436"])
139140

140141

141142
def pytest_addoption(parser):

tools/azure-sdk-tools/devtools_testutils/proxy_fixtures.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .helpers import get_test_id, is_live, is_live_and_not_recording
2424
from .proxy_testcase import start_record_or_playback, stop_record_or_playback, transform_request
2525
from .proxy_startup import test_proxy
26-
from .sanitizers import add_general_string_sanitizer
26+
from .sanitizers import add_batch_sanitizers, add_general_string_sanitizer, Sanitizer
2727

2828
if TYPE_CHECKING:
2929
from typing import Any, Callable, Dict, Optional, Tuple
@@ -55,7 +55,7 @@ def sanitize(self, variable: str, value: str) -> str:
5555
self._fake_values[variable] = value
5656
real_value = os.getenv(variable)
5757
if real_value:
58-
add_general_string_sanitizer(target=real_value, value=value)
58+
add_general_string_sanitizer(target=real_value, value=value, function_scoped=True)
5959
else:
6060
_LOGGER.info(f"No value for {variable} was found, so a sanitizer could not be registered for the variable.")
6161

@@ -70,8 +70,19 @@ def sanitize_batch(self, variables: "Dict[str, str]") -> "Dict[str, str]":
7070
:returns: A dictionary mapping environment variables to their real values in live mode, or their sanitized
7171
values in playback.
7272
"""
73-
current_values = {variable: self.sanitize(variable, variables[variable]) for variable in variables}
74-
return current_values
73+
real_values = {}
74+
sanitizers = {Sanitizer.GENERAL_STRING: []}
75+
76+
for variable in variables:
77+
self._fake_values[variable] = variables[variable]
78+
real_value = os.getenv(variable)
79+
real_values[variable] = real_value
80+
# If the variable has a value to be sanitized, add a general string sanitizer for it to our batch request
81+
if real_value:
82+
sanitizers[Sanitizer.GENERAL_STRING].append({"target": real_value, "value": variables[variable]})
83+
84+
add_batch_sanitizers(sanitizers)
85+
return real_values if is_live() else self._fake_values
7586

7687
def get(self, variable: str) -> str:
7788
"""Returns the value of the specified environment variable in live mode, or the sanitized value in playback.

tools/azure-sdk-tools/devtools_testutils/sanitizers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ def add_batch_sanitizers(sanitizers: Dict[str, List[Optional[Dict[str, str]]]],
458458
data.append(sanitizer_definition)
459459

460460
headers_to_send = {"Content-Type": "application/json"}
461+
x_recording_id = get_recording_id()
462+
if x_recording_id:
463+
headers_to_send["x-recording-id"] = x_recording_id
461464
if headers is not None:
462465
for key in headers:
463466
if headers[key] is not None:

0 commit comments

Comments
 (0)