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

[Test Proxy] Add method to reset setting customizations #24952

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions tools/azure-sdk-tools/devtools_testutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
add_uri_regex_sanitizer,
set_bodiless_matcher,
set_custom_default_matcher,
set_default_settings,
)
from .helpers import ResponseCallback, RetryCounter
from .fake_credentials import FakeTokenCredential
Expand Down Expand Up @@ -68,6 +69,7 @@
"test_proxy",
"set_bodiless_matcher",
"set_custom_default_matcher",
"set_default_settings",
"start_test_proxy",
"stop_test_proxy",
"ResponseCallback",
Expand Down
36 changes: 34 additions & 2 deletions tools/azure-sdk-tools/devtools_testutils/sanitizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def set_custom_default_matcher(**kwargs):
_send_matcher_request("CustomDefaultMatcher", {"x-recording-id": x_recording_id}, request_args)


def set_default_settings():
# type: () -> None
"""Resets all active sanitizers, matchers, and transforms for the test proxy to their default settings.

This will reset any setting customizations for a single test if it is called during test case execution, rather than
at a session, module, or class level. Otherwise, it will reset setting customizations at the session level (i.e. for
all tests).
"""

x_recording_id = get_recording_id()
_send_reset_request({"x-recording-id": x_recording_id})


def add_body_key_sanitizer(**kwargs):
# type: (**Any) -> None
"""Registers a sanitizer that offers regex update of a specific JTokenPath within a returned body.
Expand Down Expand Up @@ -228,8 +241,7 @@ def _send_matcher_request(matcher, headers, parameters=None):
# type: (str, Dict, Optional[Dict]) -> None
"""Sends a POST request to the test proxy endpoint to register the specified matcher.

If live tests are being run with recording turned off via the AZURE_SKIP_LIVE_RECORDING environment variable, no
request will be sent.
If live tests are being run, no request will be sent.

:param str matcher: The name of the matcher to set.
:param dict headers: Any matcher headers, as a dictionary.
Expand All @@ -248,6 +260,26 @@ def _send_matcher_request(matcher, headers, parameters=None):
response.raise_for_status()


def _send_reset_request(headers):
# type: (Dict) -> None
"""Sends a POST request to the test proxy endpoint to reset setting customizations.

If live tests are being run with recording turned off via the AZURE_SKIP_LIVE_RECORDING environment variable, no
request will be sent.

:param dict headers: Any reset request headers, as a dictionary.
"""

if is_live_and_not_recording():
return

response = requests.post(
"{}/Admin/Reset".format(PROXY_URL),
headers=headers
)
response.raise_for_status()


def _send_sanitizer_request(sanitizer, parameters):
# type: (str, Dict) -> None
"""Sends a POST request to the test proxy endpoint to register the specified sanitizer.
Expand Down