1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from devtools_testutils import AzureRecordedTestCase
from azure.appconfiguration import (
AzureAppConfigurationClient,
ConfigurationSetting,
FeatureFlagConfigurationSetting,
SecretReferenceConfigurationSetting,
ConfigurationSnapshot,
)
from azure.core.exceptions import ResourceExistsError
from consts import (
KEY,
LABEL,
TEST_VALUE,
TEST_CONTENT_TYPE,
)
class AppConfigTestCase(AzureRecordedTestCase):
def create_aad_client(self, appconfiguration_endpoint_string):
cred = self.get_credential(AzureAppConfigurationClient)
return AzureAppConfigurationClient(appconfiguration_endpoint_string, cred)
def create_client(self, appconfiguration_connection_string):
return AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string)
def create_config_setting(self):
return ConfigurationSetting(
key=KEY,
label=LABEL,
value=TEST_VALUE,
content_type=TEST_CONTENT_TYPE,
tags={"tag1": "value1", "tag2": "value2"},
)
def create_config_setting_no_label(self):
return ConfigurationSetting(
key=KEY,
label=None,
value=TEST_VALUE,
content_type=TEST_CONTENT_TYPE,
tags={"tag3": "value3", "tag4": "value4"},
)
def add_for_test(self, client, config_setting):
try:
client.add_configuration_setting(config_setting)
except ResourceExistsError:
pass
def set_up(self, appconfiguration_string, is_aad=False):
if is_aad:
self.client = self.create_aad_client(appconfiguration_string)
else:
self.client = self.create_client(appconfiguration_string)
self.add_for_test(self.client, self.create_config_setting())
self.add_for_test(self.client, self.create_config_setting_no_label())
def tear_down(self):
if self.client is not None:
config_settings = self.client.list_configuration_settings()
for config_setting in config_settings:
self.client.delete_configuration_setting(key=config_setting.key, label=config_setting.label)
else:
raise ValueError("Client is None!")
def _order_dict(self, d):
from collections import OrderedDict
new = OrderedDict()
for k, v in d.items():
new[k] = str(v)
return new
def _assert_same_keys(self, key1, key2):
assert type(key1) == type(key2)
assert key1.key == key2.key
assert key1.label == key2.label
assert key1.content_type == key2.content_type
assert key1.tags == key2.tags
assert key1.etag != key2.etag
assert key1.value == key2.value
if isinstance(key1, FeatureFlagConfigurationSetting):
assert key1.enabled == key2.enabled
if key1.filters and key2.filters:
assert len(key1.filters) == len(key2.filters)
assert key1.description == key2.description
elif isinstance(key1, SecretReferenceConfigurationSetting):
assert key1.secret_id == key2.secret_id
def _assert_snapshots(self, snapshot: ConfigurationSnapshot, expected_snapshot: ConfigurationSnapshot):
assert snapshot.composition_type == expected_snapshot.composition_type
assert snapshot.created == expected_snapshot.created
assert snapshot.etag == expected_snapshot.etag
assert snapshot.expires == expected_snapshot.expires
assert len(snapshot.filters) == len(expected_snapshot.filters)
for index, filter in enumerate(snapshot.filters):
assert filter.key == expected_snapshot.filters[index].key
assert filter.label == expected_snapshot.filters[index].label
assert snapshot.items_count == expected_snapshot.items_count
assert snapshot.name == expected_snapshot.name
assert snapshot.retention_period == expected_snapshot.retention_period
assert snapshot.size == expected_snapshot.size
assert snapshot.status == expected_snapshot.status
assert snapshot.tags == expected_snapshot.tags
|