From d3ceb180bc4da4b7c05bb4b24623f1226f93333f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Mon, 9 Dec 2019 16:31:58 -0800 Subject: [PATCH 1/4] fix wild cards handling --- .../_azure_appconfiguration_client.py | 29 +++++++--------- .../azure/appconfiguration/_utils.py | 27 --------------- .../aio/_azure_configuration_client_async.py | 29 +++++++--------- .../tests/test_azure_configuration_client.py | 32 +++++++++--------- .../test_azure_configuration_client_aad.py | 33 ++++++++++--------- ...st_azure_configuration_client_aad_async.py | 32 +++++++++--------- .../test_azure_configuration_client_async.py | 32 +++++++++--------- 7 files changed, 93 insertions(+), 121 deletions(-) diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py index 713abd8a7e5e..ccfed2997428 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py @@ -32,7 +32,6 @@ from ._azure_appconfiguration_credential import AppConfigConnectionStringCredential from ._utils import ( get_endpoint_from_connection_string, - escape_and_tostr, prep_if_match, prep_if_none_match, ) @@ -146,17 +145,17 @@ def _create_appconfig_pipeline(self, credential, base_url=None, aad_mode=False, @distributed_trace def list_configuration_settings( self, keys=None, labels=None, **kwargs - ): # type: (Optional[list], Optional[list], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] + ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] """List the configuration settings stored in the configuration service, optionally filtered by label and accept_datetime :param keys: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: list[str] + :type keys: str :param labels: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: list[str] + :type labels: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -177,7 +176,7 @@ def list_configuration_settings( pass # do something filtered_listed = client.list_configuration_settings( - labels=["*Labe*"], keys=["*Ke*"], accept_datetime=accept_datetime + labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime ) for item in filtered_listed: pass # do something @@ -185,16 +184,14 @@ def list_configuration_settings( select = kwargs.pop("fields", None) if select: select = ['locked' if x == 'read_only' else x for x in select] - encoded_labels = escape_and_tostr(labels) - encoded_keys = escape_and_tostr(keys) error_map = { 401: ClientAuthenticationError } try: return self._impl.get_key_values( - label=encoded_labels, - key=encoded_keys, + label=labels, + key=keys, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, @@ -438,17 +435,17 @@ def delete_configuration_setting( @distributed_trace def list_revisions( self, keys=None, labels=None, **kwargs - ): # type: (Optional[list], Optional[list], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] + ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] """ Find the ConfigurationSetting revision history. :param keys: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: list[str] + :type keys: str :param labels: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: list[str] + :type labels: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -469,7 +466,7 @@ def list_revisions( pass # do something filtered_revisions = client.list_revisions( - labels=["*Labe*"], keys=["*Ke*"], accept_datetime=accept_datetime + labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime ) for item in filtered_revisions: pass # do something @@ -477,16 +474,14 @@ def list_revisions( select = kwargs.pop("fields", None) if select: select = ['locked' if x == 'read_only' else x for x in select] - encoded_labels = escape_and_tostr(labels) - encoded_keys = escape_and_tostr(keys) error_map = { 401: ClientAuthenticationError } try: return self._impl.get_revisions( - label=encoded_labels, - key=encoded_keys, + label=labels, + key=keys, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py index 413c8e85dd5f..cc6f07be992b 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py @@ -5,35 +5,8 @@ # ------------------------------------------------------------------------- from datetime import datetime -import re from azure.core import MatchConditions -def escape_reserved(value): - """ - Reserved characters are star(*), comma(,) and backslash(\\) - If a reserved character is part of the value, then it must be escaped using \\{Reserved Character}. - Non-reserved characters can also be escaped. - - """ - if value is None: - return None - if value == "": - return "\0" # '\0' will be encoded to %00 in the url. - if isinstance(value, list): - return [escape_reserved(s) for s in value] - value = str(value) # value is unicode for Python 2.7 - # precede all reserved characters with a backslash. - # But if a * is at the beginning or the end, don't add the backslash - return re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", value) - -def escape_and_tostr(value): - if value is None: - return None - if value == [None]: - return None - value = escape_reserved(value) - return ','.join(value) - def quote_etag(etag): if not etag or etag == "*": return etag diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py index 592158ae7646..379997561e8a 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py @@ -26,7 +26,6 @@ from .._azure_appconfiguration_error import ResourceReadOnlyError from .._utils import ( get_endpoint_from_connection_string, - escape_and_tostr, prep_if_match, prep_if_none_match, ) @@ -156,17 +155,17 @@ def _create_appconfig_pipeline(self, credential, base_url=None, aad_mode=False, @distributed_trace def list_configuration_settings( self, keys=None, labels=None, **kwargs - ): # type: (list, list, dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] + ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] """List the configuration settings stored in the configuration service, optionally filtered by label and accept_datetime :param keys: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: list[str] + :type keys: str :param labels: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: list[str] + :type labels: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -187,7 +186,7 @@ def list_configuration_settings( pass # do something filtered_listed = async_client.list_configuration_settings( - labels=["*Labe*"], keys=["*Ke*"], accept_datetime=accept_datetime + labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime ) async for item in filtered_listed: pass # do something @@ -195,16 +194,14 @@ def list_configuration_settings( select = kwargs.pop("fields", None) if select: select = ['locked' if x == 'read_only' else x for x in select] - encoded_labels = escape_and_tostr(labels) - encoded_keys = escape_and_tostr(keys) error_map = { 401: ClientAuthenticationError } try: return self._impl.get_key_values( - label=encoded_labels, - key=encoded_keys, + label=labels, + key=keys, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, @@ -454,17 +451,17 @@ async def delete_configuration_setting( @distributed_trace def list_revisions( self, keys=None, labels=None, **kwargs - ): # type: (Optional[list], Optional[list], dict) -> azure.core.paging.AsyncItemPaged[ConfigurationSetting] + ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.AsyncItemPaged[ConfigurationSetting] """ Find the ConfigurationSetting revision history. :param keys: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: list[str] + :type keys: str :param labels: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: list[str] + :type labels: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -486,7 +483,7 @@ def list_revisions( pass # do something filtered_revisions = async_client.list_revisions( - labels=["*Labe*"], keys=["*Ke*"], accept_datetime=accept_datetime + labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime ) async for item in filtered_revisions: pass # do something @@ -494,16 +491,14 @@ def list_revisions( select = kwargs.pop("fields", None) if select: select = ['locked' if x == 'read_only' else x for x in select] - encoded_labels = escape_and_tostr(labels) - encoded_keys = escape_and_tostr(keys) error_map = { 401: ClientAuthenticationError } try: return self._impl.get_revisions( - label=encoded_labels, - key=encoded_keys, + label=labels, + key=keys, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py index 05f9511bce71..497616abb0ab 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py @@ -29,6 +29,7 @@ import datetime import os import logging +import re class AppConfigurationClientTest(AzureMgmtTestCase): def __init__(self, method_name): @@ -73,7 +74,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=[kv.key], labels=[kv.label] + keys=kv.key, labels=kv.label ) ) ) @@ -253,7 +254,7 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( - labels=[LABEL], keys=[KEY] + labels=LABEL, keys=KEY ) cnt = 0 for kv in items: @@ -262,7 +263,7 @@ def test_list_configuration_settings_key_label(self): assert cnt == 1 def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=[LABEL]) + items = self.app_config_client.list_configuration_settings(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -270,7 +271,7 @@ def test_list_configuration_settings_only_label(self): assert cnt == 1 def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=[KEY]) + items = self.app_config_client.list_configuration_settings(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -279,7 +280,7 @@ def test_list_configuration_settings_only_key(self): def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) cnt = 0 for kv in items: @@ -297,8 +298,9 @@ def test_list_configuration_settings_reserved_chars(self): resered_char_kv ) self.to_delete.append(resered_char_kv) + escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = self.app_config_client.list_configuration_settings( - labels=[LABEL_RESERVED_CHARS] + labels=escaped_label ) cnt = 0 for kv in items: @@ -308,7 +310,7 @@ def test_list_configuration_settings_reserved_chars(self): def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( - labels=["*" + LABEL + "*"] + labels="*" + LABEL + "*" ) cnt = 0 for kv in items: @@ -320,7 +322,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_configuration_settings( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: @@ -343,7 +345,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys=["multi_*"]) + items = self.app_config_client.list_configuration_settings(keys="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -358,7 +360,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels=[""]) + items = self.app_config_client.list_configuration_settings(labels="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -372,7 +374,7 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = self.app_config_client.list_revisions( - labels=[to_list1.label], keys=[to_list1.key] + labels=to_list1.label, keys=to_list1.key ) cnt = 0 for kv in items: @@ -381,7 +383,7 @@ def test_list_revisions_key_label(self): assert cnt >= 2 def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=[LABEL]) + items = self.app_config_client.list_revisions(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -389,7 +391,7 @@ def test_list_revisions_only_label(self): assert cnt >= 1 def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=[KEY]) + items = self.app_config_client.list_revisions(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -398,7 +400,7 @@ def test_list_revisions_key_no_label(self): def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) for kv in items: assert ( @@ -413,7 +415,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_revisions( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py index 466f6f05fad4..5e0e5681703a 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py @@ -30,6 +30,8 @@ import datetime import os import logging +import re + try: from unittest.mock import Mock except ImportError: # python < 3.3 @@ -81,7 +83,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=[kv.key], labels=[kv.label] + keys=kv.key, labels=kv.label ) ) ) @@ -261,7 +263,7 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( - labels=[LABEL], keys=[KEY] + labels=LABEL, keys=KEY ) cnt = 0 for kv in items: @@ -270,7 +272,7 @@ def test_list_configuration_settings_key_label(self): assert cnt == 1 def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=[LABEL]) + items = self.app_config_client.list_configuration_settings(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -278,7 +280,7 @@ def test_list_configuration_settings_only_label(self): assert cnt == 1 def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=[KEY]) + items = self.app_config_client.list_configuration_settings(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -287,7 +289,7 @@ def test_list_configuration_settings_only_key(self): def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) cnt = 0 for kv in items: @@ -305,8 +307,9 @@ def test_list_configuration_settings_reserved_chars(self): resered_char_kv ) self.to_delete.append(resered_char_kv) + escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = self.app_config_client.list_configuration_settings( - labels=[LABEL_RESERVED_CHARS] + labels=escaped_label ) cnt = 0 for kv in items: @@ -316,7 +319,7 @@ def test_list_configuration_settings_reserved_chars(self): def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( - labels=["*" + LABEL + "*"] + labels="*" + LABEL + "*" ) cnt = 0 for kv in items: @@ -328,7 +331,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_configuration_settings( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: @@ -351,7 +354,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys=["multi_*"]) + items = self.app_config_client.list_configuration_settings(keys="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -366,7 +369,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels=[""]) + items = self.app_config_client.list_configuration_settings(labels="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -380,7 +383,7 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = self.app_config_client.list_revisions( - labels=[to_list1.label], keys=[to_list1.key] + labels=to_list1.label, keys=to_list1.key ) cnt = 0 for kv in items: @@ -389,7 +392,7 @@ def test_list_revisions_key_label(self): assert cnt >= 2 def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=[LABEL]) + items = self.app_config_client.list_revisions(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -397,7 +400,7 @@ def test_list_revisions_only_label(self): assert cnt >= 1 def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=[KEY]) + items = self.app_config_client.list_revisions(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -406,7 +409,7 @@ def test_list_revisions_key_no_label(self): def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) for kv in items: assert ( @@ -421,7 +424,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_revisions( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py index fb040e533325..7042d65a0f41 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py @@ -34,6 +34,7 @@ from unittest.mock import Mock from azure.core.credentials import AccessToken import asyncio +import re class AppConfigurationClientTest(AzureMgmtTestCase): def __init__(self, method_name): @@ -81,7 +82,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=[kv.key], labels=[kv.label] + keys=kv.key, labels=kv.label ) ) ) @@ -261,7 +262,7 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( - labels=[LABEL], keys=[KEY] + labels=LABEL, keys=KEY ) cnt = 0 for kv in items: @@ -270,7 +271,7 @@ def test_list_configuration_settings_key_label(self): assert cnt == 1 def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=[LABEL]) + items = self.app_config_client.list_configuration_settings(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -278,7 +279,7 @@ def test_list_configuration_settings_only_label(self): assert cnt == 1 def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=[KEY]) + items = self.app_config_client.list_configuration_settings(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -287,7 +288,7 @@ def test_list_configuration_settings_only_key(self): def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) cnt = 0 for kv in items: @@ -305,8 +306,9 @@ def test_list_configuration_settings_reserved_chars(self): resered_char_kv ) self.to_delete.append(resered_char_kv) + escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = self.app_config_client.list_configuration_settings( - labels=[LABEL_RESERVED_CHARS] + labels=escaped_label ) cnt = 0 for kv in items: @@ -316,7 +318,7 @@ def test_list_configuration_settings_reserved_chars(self): def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( - labels=["*" + LABEL + "*"] + labels="*" + LABEL + "*" ) cnt = 0 for kv in items: @@ -328,7 +330,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_configuration_settings( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: @@ -351,7 +353,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys=["multi_*"]) + items = self.app_config_client.list_configuration_settings(keys="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -366,7 +368,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels=[""]) + items = self.app_config_client.list_configuration_settings(labels="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -380,7 +382,7 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = self.app_config_client.list_revisions( - labels=[to_list1.label], keys=[to_list1.key] + labels=to_list1.label, keys=to_list1.key ) cnt = 0 for kv in items: @@ -389,7 +391,7 @@ def test_list_revisions_key_label(self): assert cnt >= 2 def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=[LABEL]) + items = self.app_config_client.list_revisions(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -397,7 +399,7 @@ def test_list_revisions_only_label(self): assert cnt >= 1 def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=[KEY]) + items = self.app_config_client.list_revisions(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -406,7 +408,7 @@ def test_list_revisions_key_no_label(self): def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) for kv in items: assert ( @@ -421,7 +423,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_revisions( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py index 548b772013cf..428356208a2d 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py @@ -30,6 +30,7 @@ import datetime import os import logging +import re class AppConfigurationClientTest(AzureMgmtTestCase): def __init__(self, method_name): @@ -75,7 +76,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=[kv.key], labels=[kv.label] + keys=kv.key, labels=kv.label ) ) ) @@ -255,7 +256,7 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( - labels=[LABEL], keys=[KEY] + labels=LABEL, keys=KEY ) cnt = 0 for kv in items: @@ -264,7 +265,7 @@ def test_list_configuration_settings_key_label(self): assert cnt == 1 def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=[LABEL]) + items = self.app_config_client.list_configuration_settings(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -272,7 +273,7 @@ def test_list_configuration_settings_only_label(self): assert cnt == 1 def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=[KEY]) + items = self.app_config_client.list_configuration_settings(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -281,7 +282,7 @@ def test_list_configuration_settings_only_key(self): def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) cnt = 0 for kv in items: @@ -299,8 +300,9 @@ def test_list_configuration_settings_reserved_chars(self): resered_char_kv ) self.to_delete.append(resered_char_kv) + escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = self.app_config_client.list_configuration_settings( - labels=[LABEL_RESERVED_CHARS] + labels=escaped_label ) cnt = 0 for kv in items: @@ -310,7 +312,7 @@ def test_list_configuration_settings_reserved_chars(self): def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( - labels=["*" + LABEL + "*"] + labels="*" + LABEL + "*" ) cnt = 0 for kv in items: @@ -322,7 +324,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_configuration_settings( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: @@ -345,7 +347,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys=["multi_*"]) + items = self.app_config_client.list_configuration_settings(keys="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -360,7 +362,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels=[""]) + items = self.app_config_client.list_configuration_settings(labels="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -374,7 +376,7 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = self.app_config_client.list_revisions( - labels=[to_list1.label], keys=[to_list1.key] + labels=to_list1.label, keys=to_list1.key ) cnt = 0 for kv in items: @@ -383,7 +385,7 @@ def test_list_revisions_key_label(self): assert cnt >= 2 def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=[LABEL]) + items = self.app_config_client.list_revisions(labels=LABEL) cnt = 0 for kv in items: assert kv.label == LABEL @@ -391,7 +393,7 @@ def test_list_revisions_only_label(self): assert cnt >= 1 def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=[KEY]) + items = self.app_config_client.list_revisions(keys=KEY) cnt = 0 for kv in items: assert kv.key == KEY @@ -400,7 +402,7 @@ def test_list_revisions_key_no_label(self): def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( - keys=["*"], labels=[LABEL], fields=["key", "content_type"] + keys="*", labels=LABEL, fields=["key", "content_type"] ) for kv in items: assert ( @@ -415,7 +417,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_revisions( - keys=[to_list_kv.key], labels=[to_list_kv.label], headers=custom_headers + keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) cnt = 0 for kv in items: From e05d09a13c5b7d00a318c15f3df9ec53386ddc9f Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Tue, 10 Dec 2019 12:12:03 -0800 Subject: [PATCH 2/4] update tests --- .../tests/test_azure_configuration_client.py | 128 ++++++------------ .../test_azure_configuration_client_aad.py | 128 ++++++------------ ...st_azure_configuration_client_aad_async.py | 94 ++++--------- .../test_azure_configuration_client_async.py | 88 ++++-------- 4 files changed, 138 insertions(+), 300 deletions(-) diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py index 497616abb0ab..926a37594a17 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py @@ -253,42 +253,28 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( labels=LABEL, keys=KEY - ) - cnt = 0 - for kv in items: - assert kv.key == KEY and kv.label == LABEL - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.label == LABEL and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + items = list(self.app_config_client.list_configuration_settings(labels=LABEL)) + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + items = list(self.app_config_client.list_configuration_settings(keys=KEY)) + assert len(items) == 2 + assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( keys="*", labels=LABEL, fields=["key", "content_type"] - ) - cnt = 0 - for kv in items: - assert ( - kv.key is not None and kv.label is None and kv.content_type is not None - ) - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.key and not x.label and x.content_type for x in items) def test_list_configuration_settings_reserved_chars(self): resered_char_kv = ConfigurationSetting( @@ -299,36 +285,27 @@ def test_list_configuration_settings_reserved_chars(self): ) self.to_delete.append(resered_char_kv) escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( labels=escaped_label - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL_RESERVED_CHARS - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( labels="*" + LABEL + "*" - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers - ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_list_configuration_settings_multi_pages(self): # create PAGE_SIZE+1 configuration settings to have at least two pages @@ -373,55 +350,36 @@ def test_list_configuration_settings_only_accepttime(self): # method: list_revisions def test_list_revisions_key_label(self): to_list1 = self.test_config_setting - items = self.app_config_client.list_revisions( + items = list(self.app_config_client.list_revisions( labels=to_list1.label, keys=to_list1.key - ) - cnt = 0 - for kv in items: - assert kv.key == to_list1.key and kv.label == to_list1.label - cnt += 1 - assert cnt >= 2 + )) + assert len(items) >= 2 + assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt >= 1 + items = list(self.app_config_client.list_revisions(labels=LABEL)) + assert len(items) >= 1 + assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt >= 1 + items = list(self.app_config_client.list_revisions(keys=KEY)) + assert len(items) >= 1 + assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): - items = self.app_config_client.list_revisions( + items = list(self.app_config_client.list_revisions( keys="*", labels=LABEL, fields=["key", "content_type"] - ) - for kv in items: - assert ( - kv.key is not None - and kv.label is None - and kv.content_type is not None - and not kv.tags - and not kv.etag - ) + )) + assert all(x.key and not x.label and x.content_type and not x.tags and not x.etag for x in items) def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} - items = self.app_config_client.list_revisions( + items = list(self.app_config_client.list_revisions( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers - ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt > 0 + )) + assert len(items) >= 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_read_only(self): kv = self.test_config_setting_no_label diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py index 5e0e5681703a..8c73ebcf2b57 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py @@ -262,42 +262,28 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( labels=LABEL, keys=KEY - ) - cnt = 0 - for kv in items: - assert kv.key == KEY and kv.label == LABEL - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.key == KEY and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + items = list(self.app_config_client.list_configuration_settings(labels=LABEL)) + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + items = list(self.app_config_client.list_configuration_settings(keys=KEY)) + assert len(items) == 2 + assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( keys="*", labels=LABEL, fields=["key", "content_type"] - ) - cnt = 0 - for kv in items: - assert ( - kv.key is not None and kv.label is None and kv.content_type is not None - ) - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.key and not x.label and x.content_type for x in items) def test_list_configuration_settings_reserved_chars(self): resered_char_kv = ConfigurationSetting( @@ -308,36 +294,27 @@ def test_list_configuration_settings_reserved_chars(self): ) self.to_delete.append(resered_char_kv) escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( labels=escaped_label - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL_RESERVED_CHARS - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( labels="*" + LABEL + "*" - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} - items = self.app_config_client.list_configuration_settings( + items = list(self.app_config_client.list_configuration_settings( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers - ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt == 1 + )) + assert len(items) == 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_list_configuration_settings_multi_pages(self): # create PAGE_SIZE+1 configuration settings to have at least two pages @@ -382,55 +359,36 @@ def test_list_configuration_settings_only_accepttime(self): # method: list_revisions def test_list_revisions_key_label(self): to_list1 = self.test_config_setting - items = self.app_config_client.list_revisions( + items = list(self.app_config_client.list_revisions( labels=to_list1.label, keys=to_list1.key - ) - cnt = 0 - for kv in items: - assert kv.key == to_list1.key and kv.label == to_list1.label - cnt += 1 - assert cnt >= 2 + )) + assert len(items) >= 2 + assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt >= 1 + items = list(self.app_config_client.list_revisions(labels=LABEL)) + assert len(items) >= 1 + assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt >= 1 + items = list(self.app_config_client.list_revisions(keys=KEY)) + assert len(items) >= 1 + assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): - items = self.app_config_client.list_revisions( + items = list(self.app_config_client.list_revisions( keys="*", labels=LABEL, fields=["key", "content_type"] - ) - for kv in items: - assert ( - kv.key is not None - and kv.label is None - and kv.content_type is not None - and not kv.tags - and not kv.etag - ) + )) + assert all(x.key and not x.label and x.content_type and not x.tags and not x.etag for x in items) def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} - items = self.app_config_client.list_revisions( + items = list(self.app_config_client.list_revisions( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers - ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt > 0 + )) + assert len(items) >= 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_read_only(self): kv = self.test_config_setting_no_label diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py index 7042d65a0f41..f37855ee6c9c 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py @@ -264,39 +264,28 @@ def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( labels=LABEL, keys=KEY ) - cnt = 0 - for kv in items: - assert kv.key == KEY and kv.label == LABEL - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.key == KEY and x.label == LABEL for x in items) + def test_list_configuration_settings_only_label(self): items = self.app_config_client.list_configuration_settings(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.label == LABEL for x in items) + def test_list_configuration_settings_only_key(self): items = self.app_config_client.list_configuration_settings(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + assert len(items) == 2 + assert all(x.key == KEY for x in items) + def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( keys="*", labels=LABEL, fields=["key", "content_type"] ) - cnt = 0 - for kv in items: - assert ( - kv.key is not None and kv.label is None and kv.content_type is not None - ) - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.key and not x.label and x.content_type for x in items) def test_list_configuration_settings_reserved_chars(self): resered_char_kv = ConfigurationSetting( @@ -310,21 +299,15 @@ def test_list_configuration_settings_reserved_chars(self): items = self.app_config_client.list_configuration_settings( labels=escaped_label ) - cnt = 0 - for kv in items: - assert kv.label == LABEL_RESERVED_CHARS - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( labels="*" + LABEL + "*" ) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting @@ -332,11 +315,8 @@ def test_list_configuration_settings_correct_etag(self): items = self.app_config_client.list_configuration_settings( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_list_configuration_settings_multi_pages(self): # create PAGE_SIZE+1 configuration settings to have at least two pages @@ -384,40 +364,27 @@ def test_list_revisions_key_label(self): items = self.app_config_client.list_revisions( labels=to_list1.label, keys=to_list1.key ) - cnt = 0 - for kv in items: - assert kv.key == to_list1.key and kv.label == to_list1.label - cnt += 1 - assert cnt >= 2 + assert len(items) >= 2 + assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): items = self.app_config_client.list_revisions(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt >= 1 + assert len(items) >= 1 + assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): items = self.app_config_client.list_revisions(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt >= 1 + assert len(items) >= 1 + assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( keys="*", labels=LABEL, fields=["key", "content_type"] ) - for kv in items: - assert ( - kv.key is not None - and kv.label is None - and kv.content_type is not None - and not kv.tags - and not kv.etag - ) + assert all( + x.key and not x.label and x.content_type + and not x.tags and not x.etag + for x in items) def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting @@ -425,11 +392,8 @@ def test_list_revisions_correct_etag(self): items = self.app_config_client.list_revisions( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt > 0 + assert len(items) >= 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_read_only(self): kv = self.test_config_setting_no_label diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py index 428356208a2d..867c7c1cb1af 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py @@ -258,39 +258,25 @@ def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( labels=LABEL, keys=KEY ) - cnt = 0 - for kv in items: - assert kv.key == KEY and kv.label == LABEL - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.key == KEY and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): items = self.app_config_client.list_configuration_settings(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): items = self.app_config_client.list_configuration_settings(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + assert len(items) == 2 + assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( keys="*", labels=LABEL, fields=["key", "content_type"] ) - cnt = 0 - for kv in items: - assert ( - kv.key is not None and kv.label is None and kv.content_type is not None - ) - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.key and not x.label and x.content_type for x in items) def test_list_configuration_settings_reserved_chars(self): resered_char_kv = ConfigurationSetting( @@ -304,21 +290,15 @@ def test_list_configuration_settings_reserved_chars(self): items = self.app_config_client.list_configuration_settings( labels=escaped_label ) - cnt = 0 - for kv in items: - assert kv.label == LABEL_RESERVED_CHARS - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( labels="*" + LABEL + "*" ) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.label == LABEL for x in items) def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting @@ -326,11 +306,8 @@ def test_list_configuration_settings_correct_etag(self): items = self.app_config_client.list_configuration_settings( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt == 1 + assert len(items) == 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_list_configuration_settings_multi_pages(self): # create PAGE_SIZE+1 configuration settings to have at least two pages @@ -378,40 +355,24 @@ def test_list_revisions_key_label(self): items = self.app_config_client.list_revisions( labels=to_list1.label, keys=to_list1.key ) - cnt = 0 - for kv in items: - assert kv.key == to_list1.key and kv.label == to_list1.label - cnt += 1 - assert cnt >= 2 + assert len(items) >= 2 + assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): items = self.app_config_client.list_revisions(labels=LABEL) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt >= 1 + assert len(items) >= 1 + assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): items = self.app_config_client.list_revisions(keys=KEY) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt >= 1 + assert len(items) >= 1 + assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( keys="*", labels=LABEL, fields=["key", "content_type"] ) - for kv in items: - assert ( - kv.key is not None - and kv.label is None - and kv.content_type is not None - and not kv.tags - and not kv.etag - ) + assert all(x.key and not x.label and x.content_type and not x.tags and not x.etag for x in items) def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting @@ -419,11 +380,8 @@ def test_list_revisions_correct_etag(self): items = self.app_config_client.list_revisions( keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers ) - cnt = 0 - for kv in items: - assert kv.key == to_list_kv.key and kv.label == to_list_kv.label - cnt += 1 - assert cnt > 0 + assert len(items) >= 1 + assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) def test_read_only(self): kv = self.test_config_setting_no_label From c7e9764cf62d8951ea26a30207b244adb872ec10 Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 11 Dec 2019 11:46:02 -0800 Subject: [PATCH 3/4] rename keys/labels to key_filter/label_filter --- .../_azure_appconfiguration_client.py | 32 +++---- .../aio/_azure_configuration_client_async.py | 32 +++---- .../tests/app_configuration_preparer.py | 90 +++++++++++++++++++ .../tests/async_proxy.py | 12 +-- .../tests/test_azure_configuration_client.py | 30 +++---- .../test_azure_configuration_client_aad.py | 30 +++---- ...st_azure_configuration_client_aad_async.py | 30 +++---- .../test_azure_configuration_client_async.py | 30 +++---- 8 files changed, 188 insertions(+), 98 deletions(-) create mode 100644 sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py index ccfed2997428..1323a894d60a 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py @@ -144,18 +144,18 @@ def _create_appconfig_pipeline(self, credential, base_url=None, aad_mode=False, @distributed_trace def list_configuration_settings( - self, keys=None, labels=None, **kwargs + self, key_filter=None, label_filter=None, **kwargs ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] """List the configuration settings stored in the configuration service, optionally filtered by label and accept_datetime - :param keys: filter results based on their keys. '*' can be + :param key_filter: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: str - :param labels: filter results based on their label. '*' can be + :type key_filter: str + :param label_filter: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: str + :type label_filter: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -176,7 +176,7 @@ def list_configuration_settings( pass # do something filtered_listed = client.list_configuration_settings( - labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime + label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime ) for item in filtered_listed: pass # do something @@ -190,8 +190,8 @@ def list_configuration_settings( try: return self._impl.get_key_values( - label=labels, - key=keys, + label=label_filter, + key=key_filter, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, @@ -434,18 +434,18 @@ def delete_configuration_setting( @distributed_trace def list_revisions( - self, keys=None, labels=None, **kwargs + self, key_filter=None, label_filter=None, **kwargs ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] """ Find the ConfigurationSetting revision history. - :param keys: filter results based on their keys. '*' can be + :param key_filter: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: str - :param labels: filter results based on their label. '*' can be + :type key_filter: str + :param label_filter: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: str + :type label_filter: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -466,7 +466,7 @@ def list_revisions( pass # do something filtered_revisions = client.list_revisions( - labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime + label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime ) for item in filtered_revisions: pass # do something @@ -480,8 +480,8 @@ def list_revisions( try: return self._impl.get_revisions( - label=labels, - key=keys, + label=label_filter, + key=key_filter, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py index 379997561e8a..fcc586176ffb 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py @@ -154,18 +154,18 @@ def _create_appconfig_pipeline(self, credential, base_url=None, aad_mode=False, @distributed_trace def list_configuration_settings( - self, keys=None, labels=None, **kwargs + self, key_filter=None, label_filter=None, **kwargs ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] """List the configuration settings stored in the configuration service, optionally filtered by label and accept_datetime - :param keys: filter results based on their keys. '*' can be + :param key_filter: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: str - :param labels: filter results based on their label. '*' can be + :type key_filter: str + :param label_filter: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: str + :type label_filter: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -186,7 +186,7 @@ def list_configuration_settings( pass # do something filtered_listed = async_client.list_configuration_settings( - labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime + label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime ) async for item in filtered_listed: pass # do something @@ -200,8 +200,8 @@ def list_configuration_settings( try: return self._impl.get_key_values( - label=labels, - key=keys, + label=label_filter, + key=key_filter, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, @@ -450,18 +450,18 @@ async def delete_configuration_setting( @distributed_trace def list_revisions( - self, keys=None, labels=None, **kwargs + self, key_filter=None, label_filter=None, **kwargs ): # type: (Optional[str], Optional[str], dict) -> azure.core.paging.AsyncItemPaged[ConfigurationSetting] """ Find the ConfigurationSetting revision history. - :param keys: filter results based on their keys. '*' can be + :param key_filter: filter results based on their keys. '*' can be used as wildcard in the beginning or end of the filter - :type keys: str - :param labels: filter results based on their label. '*' can be + :type key_filter: str + :param label_filter: filter results based on their label. '*' can be used as wildcard in the beginning or end of the filter - :type labels: str + :type label_filter: str :keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime :keyword list[str] fields: specify which fields to include in the results. Leave None to include all fields :keyword dict headers: if "headers" exists, its value (a dict) will be added to the http request header @@ -483,7 +483,7 @@ def list_revisions( pass # do something filtered_revisions = async_client.list_revisions( - labels="*Labe*", keys="*Ke*", accept_datetime=accept_datetime + label_filter="*Labe*", key_filter="*Ke*", accept_datetime=accept_datetime ) async for item in filtered_revisions: pass # do something @@ -497,8 +497,8 @@ def list_revisions( try: return self._impl.get_revisions( - label=labels, - key=keys, + label=label_filter, + key=key_filter, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py b/sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py new file mode 100644 index 000000000000..eb421d39907a --- /dev/null +++ b/sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py @@ -0,0 +1,90 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +import azure.mgmt.appconfiguration +import time +import os +from devtools_testutils import AzureMgmtPreparer, ResourceGroupPreparer +from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM +from azure_devtools.scenario_tests.exceptions import AzureTestError +from azure.appconfiguration import AzureAppConfigurationClient +try: + from unittest.mock import Mock +except ImportError: # python < 3.3 + from mock import Mock +from azure.core.credentials import AccessToken + +class AppConfigurationPreparer(AzureMgmtPreparer): + def __init__(self, + name_prefix="appconfig", + parameter_name="app_config_client", + aad_mode=False, + resource_group_parameter_name=RESOURCE_GROUP_PARAM, + disable_recording=True, + playback_fake_resource=None, + client_kwargs=None): + super(AppConfigurationPreparer, self).__init__( + name_prefix, + 24, + disable_recording=disable_recording, + playback_fake_resource=playback_fake_resource, + client_kwargs=client_kwargs, + ) + self.resource_group_parameter_name = resource_group_parameter_name + self.parameter_name = parameter_name + self.aad_mode = aad_mode + + def _get_resource_group(self, **kwargs): + try: + return kwargs[self.resource_group_parameter_name] + except KeyError: + template = ( + "To create a key vault a resource group is required. Please add " + "decorator @{} in front of this storage account preparer." + ) + raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) + + def create_resource(self, name, **kwargs): + #self.client_oid = self.test_class_instance.set_value_to_scrub("CLIENT_OID", CLIENT_OID) + if self.is_live: + BODY = { + "location": "westus", + "sku": { + "name": "Free" + } + } + group = self._get_resource_group(**kwargs).name + self.mgmt_client = self.create_mgmt_client( + azure.mgmt.appconfiguration.AppConfigurationManagementClient + ) + result = self.mgmt_client.configuration_stores.create(group, name, BODY) + + # ARM may return not found at first even though the resource group has been created + retries = 4 + for i in range(retries): + try: + result = result.result() + if result.provisioning_state == "Succeeded": + break + except Exception as ex: + if i == retries - 1: + raise + time.sleep(3) + result = self.mgmt_client.configuration_stores.get(group, name) + result = list(self.mgmt_client.configuration_stores.list_keys(group, name)) + if len(result) > 0: + connection_str = result[0].connection_string + if self.aad_mode: + base_url = "https://fake_app_config.azconfig-test.io" + credential = Mock(get_token=lambda _: AccessToken("fake-token", 0)) + app_config_client = AzureAppConfigurationClient(base_url=base_url, credential=credential) + else: + app_config_client = AzureAppConfigurationClient.from_connection_string(connection_str) + pass + else: + # playback => we need only the uri used in the recording + vault_uri = "https://{}.vault.azure.net/".format(name) + + return {self.parameter_name: app_config_client} \ No newline at end of file diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/async_proxy.py b/sdk/appconfiguration/azure-appconfiguration/tests/async_proxy.py index f8f2ad5611f4..910803dc22a4 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/async_proxy.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/async_proxy.py @@ -48,11 +48,11 @@ def delete_configuration_setting(self, key, label=None, etag=None, **kwargs): ) def list_configuration_settings( - self, labels=None, keys=None, accept_datetime=None, fields=None, **kwargs + self, label_filter=None, key_filter=None, accept_datetime=None, fields=None, **kwargs ): paged = self.obj.list_configuration_settings( - labels=labels, - keys=keys, + label_filter=label_filter, + key_filter=key_filter, accept_datetime=accept_datetime, fields=fields, **kwargs @@ -60,11 +60,11 @@ def list_configuration_settings( return _to_list(paged) def list_revisions( - self, labels=None, keys=None, accept_datetime=None, fields=None, **kwargs + self, label_filter=None, key_filter=None, accept_datetime=None, fields=None, **kwargs ): paged = self.obj.list_revisions( - labels=labels, - keys=keys, + label_filter=label_filter, + key_filter=key_filter, accept_datetime=accept_datetime, fields=fields, **kwargs diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py index 926a37594a17..15c592bdb10e 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client.py @@ -74,7 +74,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=kv.key, labels=kv.label + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -254,24 +254,24 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = list(self.app_config_client.list_configuration_settings( - labels=LABEL, keys=KEY + label_filter=LABEL, key_filter=KEY )) assert len(items) == 1 assert all(x.label == LABEL and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): - items = list(self.app_config_client.list_configuration_settings(labels=LABEL)) + items = list(self.app_config_client.list_configuration_settings(label_filter=LABEL)) assert len(items) == 1 assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): - items = list(self.app_config_client.list_configuration_settings(keys=KEY)) + items = list(self.app_config_client.list_configuration_settings(key_filter=KEY)) assert len(items) == 2 assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): items = list(self.app_config_client.list_configuration_settings( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] )) assert len(items) == 1 assert all(x.key and not x.label and x.content_type for x in items) @@ -286,14 +286,14 @@ def test_list_configuration_settings_reserved_chars(self): self.to_delete.append(resered_char_kv) escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = list(self.app_config_client.list_configuration_settings( - labels=escaped_label + label_filter=escaped_label )) assert len(items) == 1 assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): items = list(self.app_config_client.list_configuration_settings( - labels="*" + LABEL + "*" + label_filter="*" + LABEL + "*" )) assert len(items) == 1 assert all(x.label == LABEL for x in items) @@ -302,7 +302,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = list(self.app_config_client.list_configuration_settings( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers )) assert len(items) == 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) @@ -322,7 +322,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys="multi_*") + items = self.app_config_client.list_configuration_settings(key_filter="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -337,7 +337,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels="\0") + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -351,24 +351,24 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = list(self.app_config_client.list_revisions( - labels=to_list1.label, keys=to_list1.key + label_filter=to_list1.label, key_filter=to_list1.key )) assert len(items) >= 2 assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): - items = list(self.app_config_client.list_revisions(labels=LABEL)) + items = list(self.app_config_client.list_revisions(label_filter=LABEL)) assert len(items) >= 1 assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): - items = list(self.app_config_client.list_revisions(keys=KEY)) + items = list(self.app_config_client.list_revisions(key_filter=KEY)) assert len(items) >= 1 assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): items = list(self.app_config_client.list_revisions( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] )) assert all(x.key and not x.label and x.content_type and not x.tags and not x.etag for x in items) @@ -376,7 +376,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = list(self.app_config_client.list_revisions( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers )) assert len(items) >= 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py index 8c73ebcf2b57..ea3ec7b44ffc 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad.py @@ -83,7 +83,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=kv.key, labels=kv.label + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -263,24 +263,24 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = list(self.app_config_client.list_configuration_settings( - labels=LABEL, keys=KEY + label_filter=LABEL, key_filter=KEY )) assert len(items) == 1 assert all(x.key == KEY and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): - items = list(self.app_config_client.list_configuration_settings(labels=LABEL)) + items = list(self.app_config_client.list_configuration_settings(label_filter=LABEL)) assert len(items) == 1 assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): - items = list(self.app_config_client.list_configuration_settings(keys=KEY)) + items = list(self.app_config_client.list_configuration_settings(key_filter=KEY)) assert len(items) == 2 assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): items = list(self.app_config_client.list_configuration_settings( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] )) assert len(items) == 1 assert all(x.key and not x.label and x.content_type for x in items) @@ -295,14 +295,14 @@ def test_list_configuration_settings_reserved_chars(self): self.to_delete.append(resered_char_kv) escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = list(self.app_config_client.list_configuration_settings( - labels=escaped_label + label_filter=escaped_label )) assert len(items) == 1 assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): items = list(self.app_config_client.list_configuration_settings( - labels="*" + LABEL + "*" + label_filter="*" + LABEL + "*" )) assert len(items) == 1 assert all(x.label == LABEL for x in items) @@ -311,7 +311,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = list(self.app_config_client.list_configuration_settings( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers )) assert len(items) == 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) @@ -331,7 +331,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys="multi_*") + items = self.app_config_client.list_configuration_settings(key_filter="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -346,7 +346,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels="\0") + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -360,24 +360,24 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = list(self.app_config_client.list_revisions( - labels=to_list1.label, keys=to_list1.key + label_filter=to_list1.label, key_filter=to_list1.key )) assert len(items) >= 2 assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): - items = list(self.app_config_client.list_revisions(labels=LABEL)) + items = list(self.app_config_client.list_revisions(label_filter=LABEL)) assert len(items) >= 1 assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): - items = list(self.app_config_client.list_revisions(keys=KEY)) + items = list(self.app_config_client.list_revisions(key_filter=KEY)) assert len(items) >= 1 assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): items = list(self.app_config_client.list_revisions( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] )) assert all(x.key and not x.label and x.content_type and not x.tags and not x.etag for x in items) @@ -385,7 +385,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = list(self.app_config_client.list_revisions( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers )) assert len(items) >= 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py index f37855ee6c9c..ca39495f20bd 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_aad_async.py @@ -82,7 +82,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=kv.key, labels=kv.label + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -262,27 +262,27 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( - labels=LABEL, keys=KEY + label_filter=LABEL, key_filter=KEY ) assert len(items) == 1 assert all(x.key == KEY and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=LABEL) + items = self.app_config_client.list_configuration_settings(label_filter=LABEL) assert len(items) == 1 assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=KEY) + items = self.app_config_client.list_configuration_settings(key_filter=KEY) assert len(items) == 2 assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] ) assert len(items) == 1 assert all(x.key and not x.label and x.content_type for x in items) @@ -297,14 +297,14 @@ def test_list_configuration_settings_reserved_chars(self): self.to_delete.append(resered_char_kv) escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = self.app_config_client.list_configuration_settings( - labels=escaped_label + label_filter=escaped_label ) assert len(items) == 1 assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( - labels="*" + LABEL + "*" + label_filter="*" + LABEL + "*" ) assert len(items) == 1 assert all(x.label == LABEL for x in items) @@ -313,7 +313,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_configuration_settings( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers ) assert len(items) == 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) @@ -333,7 +333,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys="multi_*") + items = self.app_config_client.list_configuration_settings(key_filter="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -348,7 +348,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels="\0") + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -362,24 +362,24 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = self.app_config_client.list_revisions( - labels=to_list1.label, keys=to_list1.key + label_filter=to_list1.label, key_filter=to_list1.key ) assert len(items) >= 2 assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=LABEL) + items = self.app_config_client.list_revisions(label_filter=LABEL) assert len(items) >= 1 assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=KEY) + items = self.app_config_client.list_revisions(key_filter=KEY) assert len(items) >= 1 assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] ) assert all( x.key and not x.label and x.content_type @@ -390,7 +390,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_revisions( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers ) assert len(items) >= 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py index 867c7c1cb1af..6af24c584e58 100644 --- a/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/tests/test_azure_configuration_client_async.py @@ -76,7 +76,7 @@ def _add_for_test(self, kv): exist = bool( list( self.app_config_client.list_configuration_settings( - keys=kv.key, labels=kv.label + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -256,24 +256,24 @@ def test_delete_wrong_etag(self): # method: list_configuration_settings def test_list_configuration_settings_key_label(self): items = self.app_config_client.list_configuration_settings( - labels=LABEL, keys=KEY + label_filter=LABEL, key_filter=KEY ) assert len(items) == 1 assert all(x.key == KEY and x.label == LABEL for x in items) def test_list_configuration_settings_only_label(self): - items = self.app_config_client.list_configuration_settings(labels=LABEL) + items = self.app_config_client.list_configuration_settings(label_filter=LABEL) assert len(items) == 1 assert all(x.label == LABEL for x in items) def test_list_configuration_settings_only_key(self): - items = self.app_config_client.list_configuration_settings(keys=KEY) + items = self.app_config_client.list_configuration_settings(key_filter=KEY) assert len(items) == 2 assert all(x.key == KEY for x in items) def test_list_configuration_settings_fields(self): items = self.app_config_client.list_configuration_settings( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] ) assert len(items) == 1 assert all(x.key and not x.label and x.content_type for x in items) @@ -288,14 +288,14 @@ def test_list_configuration_settings_reserved_chars(self): self.to_delete.append(resered_char_kv) escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) items = self.app_config_client.list_configuration_settings( - labels=escaped_label + label_filter=escaped_label ) assert len(items) == 1 assert all(x.label == LABEL_RESERVED_CHARS for x in items) def test_list_configuration_settings_contains(self): items = self.app_config_client.list_configuration_settings( - labels="*" + LABEL + "*" + label_filter="*" + LABEL + "*" ) assert len(items) == 1 assert all(x.label == LABEL for x in items) @@ -304,7 +304,7 @@ def test_list_configuration_settings_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_configuration_settings( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers ) assert len(items) == 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) @@ -324,7 +324,7 @@ def test_list_configuration_settings_multi_pages(self): ] except ResourceExistsError: pass - items = self.app_config_client.list_configuration_settings(keys="multi_*") + items = self.app_config_client.list_configuration_settings(key_filter="multi_*") assert len(list(items)) > PAGE_SIZE # Remove the configuration settings @@ -339,7 +339,7 @@ def test_list_configuration_settings_multi_pages(self): pass def test_list_configuration_settings_null_label(self): - items = self.app_config_client.list_configuration_settings(labels="\0") + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -353,24 +353,24 @@ def test_list_configuration_settings_only_accepttime(self): def test_list_revisions_key_label(self): to_list1 = self.test_config_setting items = self.app_config_client.list_revisions( - labels=to_list1.label, keys=to_list1.key + label_filter=to_list1.label, key_filter=to_list1.key ) assert len(items) >= 2 assert all(x.key == to_list1.key and x.label == to_list1.label for x in items) def test_list_revisions_only_label(self): - items = self.app_config_client.list_revisions(labels=LABEL) + items = self.app_config_client.list_revisions(label_filter=LABEL) assert len(items) >= 1 assert all(x.label == LABEL for x in items) def test_list_revisions_key_no_label(self): - items = self.app_config_client.list_revisions(keys=KEY) + items = self.app_config_client.list_revisions(key_filter=KEY) assert len(items) >= 1 assert all(x.key == KEY for x in items) def test_list_revisions_fields(self): items = self.app_config_client.list_revisions( - keys="*", labels=LABEL, fields=["key", "content_type"] + key_filter="*", label_filter=LABEL, fields=["key", "content_type"] ) assert all(x.key and not x.label and x.content_type and not x.tags and not x.etag for x in items) @@ -378,7 +378,7 @@ def test_list_revisions_correct_etag(self): to_list_kv = self.test_config_setting custom_headers = {"If-Match": to_list_kv.etag} items = self.app_config_client.list_revisions( - keys=to_list_kv.key, labels=to_list_kv.label, headers=custom_headers + key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers ) assert len(items) >= 1 assert all(x.key == to_list_kv.key and x.label == to_list_kv.label for x in items) From 1d8054c3ae7cddfe97ecb06bd769a9be2beb358d Mon Sep 17 00:00:00 2001 From: Xiang Yan Date: Wed, 11 Dec 2019 11:51:13 -0800 Subject: [PATCH 4/4] remove unused file --- .../tests/app_configuration_preparer.py | 90 ------------------- 1 file changed, 90 deletions(-) delete mode 100644 sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py diff --git a/sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py b/sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py deleted file mode 100644 index eb421d39907a..000000000000 --- a/sdk/appconfiguration/azure-appconfiguration/tests/app_configuration_preparer.py +++ /dev/null @@ -1,90 +0,0 @@ -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ - -import azure.mgmt.appconfiguration -import time -import os -from devtools_testutils import AzureMgmtPreparer, ResourceGroupPreparer -from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM -from azure_devtools.scenario_tests.exceptions import AzureTestError -from azure.appconfiguration import AzureAppConfigurationClient -try: - from unittest.mock import Mock -except ImportError: # python < 3.3 - from mock import Mock -from azure.core.credentials import AccessToken - -class AppConfigurationPreparer(AzureMgmtPreparer): - def __init__(self, - name_prefix="appconfig", - parameter_name="app_config_client", - aad_mode=False, - resource_group_parameter_name=RESOURCE_GROUP_PARAM, - disable_recording=True, - playback_fake_resource=None, - client_kwargs=None): - super(AppConfigurationPreparer, self).__init__( - name_prefix, - 24, - disable_recording=disable_recording, - playback_fake_resource=playback_fake_resource, - client_kwargs=client_kwargs, - ) - self.resource_group_parameter_name = resource_group_parameter_name - self.parameter_name = parameter_name - self.aad_mode = aad_mode - - def _get_resource_group(self, **kwargs): - try: - return kwargs[self.resource_group_parameter_name] - except KeyError: - template = ( - "To create a key vault a resource group is required. Please add " - "decorator @{} in front of this storage account preparer." - ) - raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) - - def create_resource(self, name, **kwargs): - #self.client_oid = self.test_class_instance.set_value_to_scrub("CLIENT_OID", CLIENT_OID) - if self.is_live: - BODY = { - "location": "westus", - "sku": { - "name": "Free" - } - } - group = self._get_resource_group(**kwargs).name - self.mgmt_client = self.create_mgmt_client( - azure.mgmt.appconfiguration.AppConfigurationManagementClient - ) - result = self.mgmt_client.configuration_stores.create(group, name, BODY) - - # ARM may return not found at first even though the resource group has been created - retries = 4 - for i in range(retries): - try: - result = result.result() - if result.provisioning_state == "Succeeded": - break - except Exception as ex: - if i == retries - 1: - raise - time.sleep(3) - result = self.mgmt_client.configuration_stores.get(group, name) - result = list(self.mgmt_client.configuration_stores.list_keys(group, name)) - if len(result) > 0: - connection_str = result[0].connection_string - if self.aad_mode: - base_url = "https://fake_app_config.azconfig-test.io" - credential = Mock(get_token=lambda _: AccessToken("fake-token", 0)) - app_config_client = AzureAppConfigurationClient(base_url=base_url, credential=credential) - else: - app_config_client = AzureAppConfigurationClient.from_connection_string(connection_str) - pass - else: - # playback => we need only the uri used in the recording - vault_uri = "https://{}.vault.azure.net/".format(name) - - return {self.parameter_name: app_config_client} \ No newline at end of file