зеркало из
1
0
Форкнуть 0
azure-sdk-for-python/tools/azure-sdk-tools/devtools_testutils
Scott Beddall 689bac0896
Remove unnecessary variable defaults (#37604)
* apply black and prepare for parsing the ci.yml so that we can understand if testproxy is enabled or disabled
* The language specific cert trust in Language-Settings has been updated to no longer globally set environment variables SSL_CERT_DIR, SSL_CERT_FILE, and REQUEST_CA_BUNDLE. These are dynamically set in proxy_startup.py
2024-09-27 11:59:35 -07:00
..
aio Remove internal `azure-devtools` references (#33492) 2023-12-14 15:24:25 -08:00
perfstress_tests Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
storage Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
README.md Update `devtools_testutils` documentation (#32259) 2023-09-27 17:05:45 -07:00
__init__.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
azure_recorded_testcase.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
azure_testcase.py Remove internal `azure-devtools` references (#33492) 2023-12-14 15:24:25 -08:00
cert.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
config.py Remove internal `azure-devtools` references (#33492) 2023-12-14 15:24:25 -08:00
envvariable_loader.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
exceptions.py Move away from `azure-devtools` test exceptions (#33273) 2023-11-28 11:11:50 -08:00
fake_credentials.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
fake_credentials_async.py Establish fake_credentials.py file for test credentials (#23001) 2022-02-11 12:12:42 -08:00
helpers.py Remove internal `azure-devtools` references (#33492) 2023-12-14 15:24:25 -08:00
mgmt_recorded_testcase.py Refactor Build, Versioning into `azure-sdk-tools` (#25454) 2022-08-16 12:25:02 -07:00
mgmt_settings_fake.py formatting tools code (#18983) 2021-05-27 17:26:28 +00:00
mgmt_test_stats.py formatting tools code (#18983) 2021-05-27 17:26:28 +00:00
mgmt_testcase.py [skip ci] Delete azure-devtools and deps/references 2024-03-26 16:33:36 -07:00
preparers.py Remove internal `azure-devtools` references (#33492) 2023-12-14 15:24:25 -08:00
proxy_fixtures.py Use batch sanitizing feature from sanitizing fixture (#36512) 2024-07-19 18:55:08 -07:00
proxy_startup.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
proxy_testcase.py [Tools] Minor fixes (#36295) 2024-06-28 16:31:34 -07:00
resource_testcase.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
sanitizers.py Remove unnecessary variable defaults (#37604) 2024-09-27 11:59:35 -07:00
setup.py Tools folder (#5734) 2019-06-07 15:46:24 -07:00
storage_testcase.py Remove internal `azure-devtools` references (#33492) 2023-12-14 15:24:25 -08:00

README.md

Devtools Testutils

Objects in this package for use with Azure Testing

Fake test credentials

devtools_testutils also provides a central location for storing and fetching fake credentials for use in tests: fake_credentials.py. Using credentials from this file helps us keep the repository free from credential leaks and false warnings from the Credential Scanner (CredScan) tool. For more information about the azure-sdk-for-python's use of CredScan, please refer to the CredScan monitoring guide.

Use the EnvironmentVariableLoader

Fetching environment variables, passing them directly to tests, and sanitizing their real values can be done all at once by using the devtools_testutils EnvironmentVariableLoader (formerly known as the PowerShellPreparer).

This loader is meant to be paired with the PowerShell test resource management commands that are documented in /eng/common/TestResources. It's recommended that all test suites use these scripts for live test resource management.

The EnvironmentVariableLoader accepts a positional directory argument and arbitrary keyword-only arguments:

  • directory is the name of your package's service as it appears in the Python repository; i.e. service in azure-sdk-for-python/sdk/service/azure-service-package.
    • For example, for azure-keyvault-keys, the value of directory is keyvault.
  • For each environment variable you want to provide to tests, pass in a keyword argument with the pattern environment_variable_name="sanitized-value".
    • For example, to fetch the value of STORAGE_ENDPOINT and sanitize this value in recordings as fake-endpoint, provide storage_endpoint="fake-endpoint" to the EnvironmentVariableLoader constructor.

Decorated test methods will have the values of environment variables passed to them as keyword arguments, and these values will automatically have sanitizers registered with the test proxy. More specifically, the true values of requested variables will be provided to tests in live mode, and the sanitized values of these variables will be provided in playback mode.

The most common way to use the EnvironmentVariableLoader is to declare a callable specifying arguments by using functools.partial and then decorate test methods with that callable. For example:

import functools
from devtools_testutils import AzureRecordedTestCase, EnvironmentVariableLoader, recorded_by_proxy

ServicePreparer = functools.partial(
    EnvironmentVariableLoader,
    "service",
    service_endpoint="fake-endpoint",
    service_account_name="fake-account-name",
)

class TestExample(AzureRecordedTestCase):

    @ServicePreparer()
    @recorded_by_proxy
    def test_example_with_preparer(self, **kwargs):
        service_endpoint = kwargs.pop("service_endpoint")
        ...

Be sure to match the formatting of live values in playback values. For example, if the actual service endpoint in your .env file doesn't end with a trailing slash (/), adding a trailing slash to your playback endpoint value will result in playback errors. The exact value of your live variables will be replaced with the exact value of your playback variables in recordings.

Note: The EnvironmentVariableLoader expects environment variables for service tests to be prefixed with the service name (e.g. KEYVAULT_ for Key Vault tests). You'll need to set environment variables for {SERVICE}_TENANT_ID, {SERVICE}_CLIENT_ID, and {SERVICE}_CLIENT_SECRET for a service principal when using this class.