-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Test Proxy] Add RecordedByProxy decorator and AzureRecordedTestCase #20138
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7d6b3a9
Add RecordedByProxy, AzureRecordedTestCase
mccoyp 98fdfa9
Use AZURE_TEST_RUN_LIVE as recording flag
mccoyp da070f4
RecordedByProxyAsync and preparer compat.
mccoyp ad60ef1
Default to playback mode
mccoyp cd2a545
Run black
mccoyp 2f7a34c
Remove debugging print statements
mccoyp 4d7f3eb
add_sanitizer (still need HTTPS default)
mccoyp 444f41e
Default to HTTPS
mccoyp d2cd0b0
Add ProxyRecordingSanitizer to __init__
mccoyp f9f7ed3
Thanks, Sean!
mccoyp e388418
Correct recording storage (thanks Scott!)
mccoyp 2d18116
Factor out get_current_sha
mccoyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,3 +114,6 @@ sdk/cosmos/azure-cosmos/test/test_config.py | |
|
|
||
| # env vars | ||
| .env | ||
|
|
||
| # local SSL certificate folder | ||
| .certificate | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .proxy_testcase_async import RecordedByProxyAsync | ||
|
|
||
| __all__ = ["RecordedByProxyAsync"] |
50 changes: 50 additions & 0 deletions
50
tools/azure-sdk-tools/devtools_testutils/aio/proxy_testcase_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from azure.core.pipeline.transport import AioHttpTransport | ||
|
|
||
| from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function | ||
| from ..proxy_testcase import ( | ||
| get_test_id, | ||
| start_record_or_playback, | ||
| transform_request, | ||
| stop_record_or_playback, | ||
| ) | ||
|
|
||
|
|
||
| def RecordedByProxyAsync(func): | ||
mccoyp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async def record_wrap(*args, **kwargs): | ||
| test_id = get_test_id() | ||
| recording_id = start_record_or_playback(test_id) | ||
|
|
||
| def transform_args(*args, **kwargs): | ||
| copied_positional_args = list(args) | ||
| request = copied_positional_args[1] | ||
|
|
||
| transform_request(request, recording_id) | ||
|
|
||
| return tuple(copied_positional_args), kwargs | ||
|
|
||
| trimmed_kwargs = {k: v for k, v in kwargs.items()} | ||
| trim_kwargs_from_test_function(func, trimmed_kwargs) | ||
|
|
||
| original_func = AioHttpTransport.send | ||
|
|
||
| async def combined_call(*args, **kwargs): | ||
| adjusted_args, adjusted_kwargs = transform_args(*args, **kwargs) | ||
| return await original_func(*adjusted_args, **adjusted_kwargs) | ||
|
|
||
| AioHttpTransport.send = combined_call | ||
|
|
||
| # call the modified function. | ||
| try: | ||
| value = await func(*args, **trimmed_kwargs) | ||
| finally: | ||
| AioHttpTransport.send = original_func | ||
| stop_record_or_playback(test_id, recording_id) | ||
|
|
||
| return value | ||
|
|
||
| return record_wrap | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would add a log as an else statement here because then the name pair will not be scrubbed from the recordings. With a log at least you are notifying the dev that the object has no scrubber object.