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..1323a894d60a 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, ) @@ -145,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 - ): # type: (Optional[list], Optional[list], dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] + 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: list[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: list[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 @@ -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 + label_filter="*Labe*", key_filter="*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=label_filter, + key=key_filter, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, @@ -437,18 +434,18 @@ 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] + 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: list[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: list[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 @@ -469,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 @@ -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=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/_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..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 @@ -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, ) @@ -155,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 - ): # type: (list, list, dict) -> azure.core.paging.ItemPaged[ConfigurationSetting] + 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: list[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: list[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 @@ -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 + label_filter="*Labe*", key_filter="*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=label_filter, + key=key_filter, select=select, cls=lambda objs: [ConfigurationSetting._from_key_value(x) for x in objs], error_map=error_map, @@ -453,18 +450,18 @@ 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] + 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: list[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: list[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 @@ -486,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 @@ -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=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/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 05f9511bce71..15c592bdb10e 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] + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -252,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( - labels=[LABEL], keys=[KEY] - ) - cnt = 0 - for kv in items: - assert kv.key == KEY and kv.label == LABEL - cnt += 1 - assert cnt == 1 + items = list(self.app_config_client.list_configuration_settings( + 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 = 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(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]) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + 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 = 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 + items = list(self.app_config_client.list_configuration_settings( + 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) def test_list_configuration_settings_reserved_chars(self): resered_char_kv = ConfigurationSetting( @@ -297,36 +284,28 @@ def test_list_configuration_settings_reserved_chars(self): resered_char_kv ) self.to_delete.append(resered_char_kv) - items = self.app_config_client.list_configuration_settings( - labels=[LABEL_RESERVED_CHARS] - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL_RESERVED_CHARS - cnt += 1 - assert cnt == 1 + escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) + items = list(self.app_config_client.list_configuration_settings( + 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 + "*"] - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + 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_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 - ) - 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 + items = list(self.app_config_client.list_configuration_settings( + 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) def test_list_configuration_settings_multi_pages(self): # create PAGE_SIZE+1 configuration settings to have at least two pages @@ -343,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 @@ -358,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=[""]) + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -371,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( - 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 + items = list(self.app_config_client.list_revisions( + 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]) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt >= 1 + 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 = 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(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"] - ) - 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 - ) + items = list(self.app_config_client.list_revisions( + 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) 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 - ) - 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 + items = list(self.app_config_client.list_revisions( + 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) 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 466f6f05fad4..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 @@ -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] + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -260,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( - labels=[LABEL], keys=[KEY] - ) - cnt = 0 - for kv in items: - assert kv.key == KEY and kv.label == LABEL - cnt += 1 - assert cnt == 1 + items = list(self.app_config_client.list_configuration_settings( + 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]) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + 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 = 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(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"] - ) - 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 + items = list(self.app_config_client.list_configuration_settings( + 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) def test_list_configuration_settings_reserved_chars(self): resered_char_kv = ConfigurationSetting( @@ -305,36 +293,28 @@ def test_list_configuration_settings_reserved_chars(self): resered_char_kv ) self.to_delete.append(resered_char_kv) - items = self.app_config_client.list_configuration_settings( - labels=[LABEL_RESERVED_CHARS] - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL_RESERVED_CHARS - cnt += 1 - assert cnt == 1 + escaped_label = re.sub(r"((?!^)\*(?!$)|\\|,)", r"\\\1", LABEL_RESERVED_CHARS) + items = list(self.app_config_client.list_configuration_settings( + 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 + "*"] - ) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt == 1 + 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_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 - ) - 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 + items = list(self.app_config_client.list_configuration_settings( + 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) def test_list_configuration_settings_multi_pages(self): # create PAGE_SIZE+1 configuration settings to have at least two pages @@ -351,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 @@ -366,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=[""]) + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -379,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( - 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 + items = list(self.app_config_client.list_revisions( + 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]) - cnt = 0 - for kv in items: - assert kv.label == LABEL - cnt += 1 - assert cnt >= 1 + 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 = 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(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"] - ) - 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 - ) + items = list(self.app_config_client.list_revisions( + 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) 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 - ) - 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 + items = list(self.app_config_client.list_revisions( + 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) 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 fb040e533325..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 @@ -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] + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -261,41 +262,30 @@ 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 ) - 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 = 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]) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + 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"] ) - 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( @@ -305,36 +295,28 @@ 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] + label_filter=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 + "*"] + label_filter="*" + 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( - 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 ) - 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 @@ -351,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 @@ -366,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=[""]) + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -380,54 +362,38 @@ 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 ) - 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 = 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]) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt >= 1 + 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"] ) - 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( - 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 ) - 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 548b772013cf..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 @@ -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] + key_filter=kv.key, label_filter=kv.label ) ) ) @@ -255,41 +256,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 ) - 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 = 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]) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt == 2 + 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"] ) - 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 +286,28 @@ 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] + label_filter=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 + "*"] + label_filter="*" + 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( - 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 ) - 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 @@ -345,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 @@ -360,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=[""]) + items = self.app_config_client.list_configuration_settings(label_filter="\0") assert len(list(items)) > 0 def test_list_configuration_settings_only_accepttime(self): @@ -374,54 +353,35 @@ 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 ) - 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 = 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]) - cnt = 0 - for kv in items: - assert kv.key == KEY - cnt += 1 - assert cnt >= 1 + 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"] ) - 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( - 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 ) - 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