-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Python functionality for Test Resources Preparer script #15227
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
43 commits
Select commit
Hold shift + click to select a range
0dd8d6f
first workings of powershell script, works with preparer as is, guida…
seankane-msft f871dff
applied to cosmos code as well, working well!
seankane-msft eff2421
adding cosmos changes, and dotenv import to show a .env
seankane-msft aa92dd4
starter code for a powershell preparer, works on a single test in sch…
seankane-msft daa316b
adding python-dotenv to dev reqs, recordings for schemareg with scrub…
seankane-msft b17de26
test resources for tables, powershell preparer
seankane-msft 0151b36
making the same change for avroserializer
seankane-msft 60e78cc
scrubbed recording for avroserializer
seankane-msft a0754d2
updating the pipeline with help of scott b, adding a step to run the …
seankane-msft 748e078
removing dotenv stuff from the azuretestcase class, keeping it strict…
seankane-msft 5719370
only setting tenant/client ids/secrets when in live mode, should prev…
seankane-msft 23b9a2a
added python-dotenv to the tables dev reqs
seankane-msft b553152
adding a preparer to appconfig, adding for one file at the moment
seankane-msft bc715ec
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-pytho…
seankane-msft 750fc35
adding all the test files to use the preparer
seankane-msft cc0c0dd
fixing merge conflict
seankane-msft 8b3f811
updating gitignore to ignore encrypted output files from New-TestReso…
seankane-msft a10b2e5
removing async code from sync tests
seankane-msft d7a4a0f
adding python-dotenv to the mgmt library too
seankane-msft 52319f8
adding an empty aditionaltestargs
seankane-msft b258a5f
removing armtemplateparameters entirely
seankane-msft cc3a83a
changed python-dotenv to a try, except. will get feedback on that dec…
seankane-msft 689c37f
removing python-dotenv changes, will go in a separate PR. removing ch…
seankane-msft b3d2b70
adding a post-script to remove test resources
seankane-msft ede47c3
addressing bens comments and removing unnecessary args
seankane-msft 1fabc1f
changed the secret to avoid credscan from flagging the repo
seankane-msft 5afcaf1
changing deploy/remove-test-resources.yml to only run if AllocateReso…
seankane-msft 2fc0ff0
AllocateResourceGroup is false in schemareg
seankane-msft e8cc4dc
merge conflicts
seankane-msft 34087fb
added a decorator for tests to remove statefulness from tests, new re…
seankane-msft c90b3e4
changing the import of SchemaRegPSPreparer to just PowerShellPreparer…
seankane-msft 336af2e
removing commented out code now that everything passes
seankane-msft 0a7027a
addressing bens comments
seankane-msft d47c8ee
removing double call on the appconfig preparer
seankane-msft ad47677
fixing merge conflicts
seankane-msft c651bfd
moved wrapper to a separate file, enabling re-use, removed unittest.T…
seankane-msft f4896dd
forgot to add wrapper files
seankane-msft f65a574
removing async portion of sync wrapper
seankane-msft 559a0b7
adding a second parameter for explicitly deploying arm template, upda…
seankane-msft 9141d80
addressing wes's comments regarding pipeline steps
seankane-msft 622bf79
changing strings(true/false) to be boolean values
seankane-msft 20de743
addressing all of laurents comments, trimming the init params in powe…
seankane-msft 5dbf8ea
addressing merge conflicts
seankane-msft 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 |
|---|---|---|
|
|
@@ -102,4 +102,4 @@ sdk/cosmos/azure-cosmos/test/test_config.py | |
| .tmp_code_path/ | ||
|
|
||
| # env vars | ||
| .env | ||
| .env | ||
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
119 changes: 119 additions & 0 deletions
119
sdk/appconfiguration/azure-appconfiguration/tests/async_wrapper.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,119 @@ | ||
|
|
||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from devtools_testutils import PowerShellPreparer | ||
|
|
||
| from azure.appconfiguration import ( | ||
| ResourceReadOnlyError, | ||
| ConfigurationSetting, | ||
| ) | ||
| from azure.appconfiguration.aio import AzureAppConfigurationClient | ||
| from azure.core.exceptions import ( | ||
| AzureError, | ||
| ) | ||
| from consts import ( | ||
| KEY, | ||
| LABEL, | ||
| TEST_VALUE, | ||
| TEST_CONTENT_TYPE, | ||
| LABEL_RESERVED_CHARS, | ||
| PAGE_SIZE, | ||
| KEY_UUID, | ||
| ) | ||
| from async_proxy import AzureAppConfigurationClientProxy | ||
| import functools | ||
| import inspect | ||
|
|
||
| AppConfigPreparer = functools.partial( | ||
| PowerShellPreparer, | ||
| 'appconfiguration', | ||
| appconfiguration_connection_string="Endpoint=https://fake_app_config.azconfig-test.io;Id=0-l4-s0:h5htBaY5Z1LwFz50bIQv;Secret=lamefakesecretlamefakesecretlamefakesecrett=", | ||
| appconfiguration_endpoint_string="https://fake_app_config.azconfig-test.io") | ||
|
|
||
| def _add_for_test(client, kv): | ||
| exist = bool( | ||
| list( | ||
| client.list_configuration_settings( | ||
| key_filter=kv.key, label_filter=kv.label | ||
| ) | ||
| ) | ||
| ) | ||
| if exist: | ||
| _delete_from_test(client, kv.key, kv.label) | ||
| return client.add_configuration_setting(kv) | ||
|
|
||
| def _delete_from_test(client, key, label): | ||
| try: | ||
| client.delete_configuration_setting(key=key, label=label) | ||
| except AzureError: | ||
| logging.debug( | ||
| "Error occurred removing configuration setting %s %s during unit test" | ||
| % (key, label) | ||
| ) | ||
|
|
||
| def trim_kwargs_from_test_function(fn, kwargs): | ||
| # the next function is the actual test function. the kwargs need to be trimmed so | ||
| # that parameters which are not required will not be passed to it. | ||
| if not getattr(fn, '__is_preparer', False): | ||
| try: | ||
| args, _, kw, _, _, _, _ = inspect.getfullargspec(fn) | ||
| except AttributeError: | ||
| args, _, kw, _ = inspect.getargspec(fn) # pylint: disable=deprecated-method | ||
| if kw is None: | ||
| args = set(args) | ||
| for key in [k for k in kwargs if k not in args]: | ||
| del kwargs[key] | ||
|
|
||
|
|
||
| def app_config_decorator(func, **kwargs): | ||
|
|
||
| @AppConfigPreparer() | ||
| def wrapper(*args, **kwargs): | ||
| appconfiguration_connection_string = kwargs.pop("appconfiguration_connection_string") | ||
| client = AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string) | ||
| client = AzureAppConfigurationClientProxy(client) | ||
|
|
||
| kwargs['client'] = client | ||
| kwargs['appconfiguration_connection_string'] = appconfiguration_connection_string | ||
|
|
||
| # Do setUp on client | ||
| test_config_setting = _add_for_test( | ||
| client, | ||
| ConfigurationSetting( | ||
| key=KEY, | ||
| label=LABEL, | ||
| value=TEST_VALUE, | ||
| content_type=TEST_CONTENT_TYPE, | ||
| tags={"tag1": "tag1", "tag2": "tag2"}, | ||
| ) | ||
| ) | ||
| test_config_setting_no_label = _add_for_test( | ||
| client, | ||
| ConfigurationSetting( | ||
| key=KEY, | ||
| label=None, | ||
| value=TEST_VALUE, | ||
| content_type=TEST_CONTENT_TYPE, | ||
| tags={"tag1": "tag1", "tag2": "tag2"}, | ||
| ) | ||
| ) | ||
| to_delete = [test_config_setting, test_config_setting_no_label] | ||
|
|
||
| kwargs['test_config_setting'] = test_config_setting | ||
| kwargs['test_config_setting_no_label'] = test_config_setting_no_label | ||
|
|
||
| trimmed_kwargs = {k:v for k, v in kwargs.items()} | ||
| trim_kwargs_from_test_function(func, trimmed_kwargs) | ||
|
|
||
| func(*args, **trimmed_kwargs) | ||
|
|
||
| # do tearDown on client | ||
| for item in to_delete: | ||
| client.delete_configuration_setting( | ||
| key=item.key, label=item.label | ||
| ) | ||
|
|
||
| return wrapper |
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.
Uh oh!
There was an error while loading. Please reload this page.