Skip to content

Commit 9299654

Browse files
author
Yalin Li
authored
[AppConfig] Refactor tests (Azure#25748)
1 parent 5e3ffb0 commit 9299654

File tree

188 files changed

+31586
-79179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+31586
-79179
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# coding: utf-8
2+
# -------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
# --------------------------------------------------------------------------
7+
from preparers import AppConfigPreparer, trim_kwargs_from_test_function
8+
9+
10+
def app_config_decorator_async(func, **kwargs):
11+
@AppConfigPreparer()
12+
async def wrapper(*args, **kwargs):
13+
appconfiguration_connection_string = kwargs.pop("appconfiguration_connection_string")
14+
kwargs['appconfiguration_connection_string'] = appconfiguration_connection_string
15+
16+
trimmed_kwargs = {k:v for k, v in kwargs.items()}
17+
trim_kwargs_from_test_function(func, trimmed_kwargs)
18+
19+
await func(*args, **trimmed_kwargs)
20+
21+
return wrapper
22+
23+
def app_config_aad_decorator_async(func, **kwargs):
24+
@AppConfigPreparer()
25+
async def wrapper(*args, **kwargs):
26+
appconfiguration_endpoint_string = kwargs.pop("appconfiguration_endpoint_string")
27+
kwargs['appconfiguration_endpoint_string'] = appconfiguration_endpoint_string
28+
29+
trimmed_kwargs = {k:v for k, v in kwargs.items()}
30+
trim_kwargs_from_test_function(func, trimmed_kwargs)
31+
32+
await func(*args, **trimmed_kwargs)
33+
34+
return wrapper

sdk/appconfiguration/azure-appconfiguration/tests/async_proxy.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

sdk/appconfiguration/azure-appconfiguration/tests/async_wrapper.py

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# coding: utf-8
2+
# -------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
# --------------------------------------------------------------------------
7+
from azure.appconfiguration.aio import (
8+
AzureAppConfigurationClient,
9+
)
10+
from testcase import AppConfigTestCase
11+
12+
13+
class AsyncAppConfigTestCase(AppConfigTestCase):
14+
def create_aad_client(self, appconfiguration_endpoint_string):
15+
cred = self.get_credential(AzureAppConfigurationClient, is_async=True)
16+
return AzureAppConfigurationClient(appconfiguration_endpoint_string, cred)
17+
18+
def create_client(self, appconfiguration_connection_string):
19+
return AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string)
20+
21+
async def add_for_test(self, client, config_setting):
22+
exist_list = await self.convert_to_list(client.list_configuration_settings(
23+
key_filter=config_setting.key, label_filter=config_setting.label
24+
))
25+
exist = bool(exist_list)
26+
if exist:
27+
await client.delete_configuration_setting(key=config_setting.key, label=config_setting.label)
28+
await client.add_configuration_setting(config_setting)
29+
30+
async def convert_to_list(self, config_settings): # type: (AsyncItemPaged) -> list
31+
list = []
32+
async for item in config_settings:
33+
list.append(item)
34+
return list
35+
36+
async def set_up(self, appconfiguration_string, is_aad=False):
37+
if is_aad:
38+
self.client = self.create_aad_client(appconfiguration_string)
39+
else:
40+
self.client = self.create_client(appconfiguration_string)
41+
await self.add_for_test(self.client, self.create_config_setting())
42+
await self.add_for_test(self.client, self.create_config_setting_no_label())
43+
44+
async def tear_down(self):
45+
if self.client is not None:
46+
config_settings = self.client.list_configuration_settings()
47+
async for config_setting in config_settings:
48+
await self.client.delete_configuration_setting(key=config_setting.key, label=config_setting.label)
49+
else:
50+
raise ValueError("Client is None!")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
# coding: utf-8
3+
# -------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
# Licensed under the MIT License. See License.txt in the project root for
6+
# license information.
7+
# --------------------------------------------------------------------------
8+
from devtools_testutils import PowerShellPreparer
9+
import functools
10+
import inspect
11+
12+
AppConfigPreparer = functools.partial(
13+
PowerShellPreparer,
14+
'appconfiguration',
15+
appconfiguration_connection_string="Endpoint=https://fake_app_config.azconfig-test.io;Id=0-l4-s0:h5htBaY5Z1LwFz50bIQv;Secret=lamefakesecretlamefakesecretlamefakesecrett=",
16+
appconfiguration_endpoint_string="https://fake_app_config.azconfig-test.io",
17+
)
18+
19+
20+
def trim_kwargs_from_test_function(fn, kwargs):
21+
# the next function is the actual test function. the kwargs need to be trimmed so
22+
# that parameters which are not required will not be passed to it.
23+
if not getattr(fn, '__is_preparer', False):
24+
try:
25+
args, _, kw, _, _, _, _ = inspect.getfullargspec(fn)
26+
except AttributeError:
27+
args, _, kw, _ = inspect.getargspec(fn) # pylint: disable=deprecated-method
28+
if kw is None:
29+
args = set(args)
30+
for key in [k for k in kwargs if k not in args]:
31+
del kwargs[key]
32+
33+
def app_config_decorator(func, **kwargs):
34+
@AppConfigPreparer()
35+
def wrapper(*args, **kwargs):
36+
appconfiguration_connection_string = kwargs.pop("appconfiguration_connection_string")
37+
kwargs['appconfiguration_connection_string'] = appconfiguration_connection_string
38+
39+
trimmed_kwargs = {k:v for k, v in kwargs.items()}
40+
trim_kwargs_from_test_function(func, trimmed_kwargs)
41+
42+
func(*args, **trimmed_kwargs)
43+
44+
return wrapper
45+
46+
def app_config_aad_decorator(func, **kwargs):
47+
@AppConfigPreparer()
48+
def wrapper(*args, **kwargs):
49+
appconfiguration_endpoint_string = kwargs.pop("appconfiguration_endpoint_string")
50+
kwargs['appconfiguration_endpoint_string'] = appconfiguration_endpoint_string
51+
52+
trimmed_kwargs = {k:v for k, v in kwargs.items()}
53+
trim_kwargs_from_test_function(func, trimmed_kwargs)
54+
55+
func(*args, **trimmed_kwargs)
56+
57+
return wrapper

0 commit comments

Comments
 (0)