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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from azure.appconfiguration import (
FeatureFlagConfigurationSetting,
FILTER_PERCENTAGE,
)
from testcase import AppConfigTestCase
from preparers import app_config_decorator
from devtools_testutils import recorded_by_proxy
import json
import pytest
class TestAppConfigurationConsistency(AppConfigTestCase):
@app_config_decorator
@recorded_by_proxy
def test_update_json_by_value(self, appconfiguration_connection_string):
client = self.create_client(appconfiguration_connection_string)
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(
key,
enabled=True,
filters=[
{
"name": FILTER_PERCENTAGE,
"parameters": {
"Value": 10,
"User": "user1"
}
}
]
)
set_flag = client.set_configuration_setting(feature_flag)
set_flag.value = json.dumps({
'conditions': {
'client_filters': [
{
'name': 'Microsoft.Targeting',
'parameters': {
'name': 'Microsoft.Targeting',
'parameters': {
'Audience': {
'DefaultRolloutPercentage': 50,
'Groups': [],
'Users': []
}
}
}
}
]
},
'description': '',
'enabled': False,
'id': key,
})
set_flag = client.set_configuration_setting(set_flag)
assert isinstance(set_flag, FeatureFlagConfigurationSetting)
assert set_flag.enabled == False
assert set_flag.key.endswith(key)
client.delete_configuration_setting(set_flag)
@app_config_decorator
@recorded_by_proxy
def test_feature_flag_invalid_json(self, appconfiguration_connection_string):
client = self.create_client(appconfiguration_connection_string)
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(key, enabled=True)
set_flag = client.set_configuration_setting(feature_flag)
with pytest.raises(TypeError):
set_flag.value = []
client.set_configuration_setting(set_flag)
client.delete_configuration_setting(feature_flag)
@app_config_decorator
@recorded_by_proxy
def test_feature_flag_invalid_json_string(self, appconfiguration_connection_string):
client = self.create_client(appconfiguration_connection_string)
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(key, enabled=True)
set_flag = client.set_configuration_setting(feature_flag)
set_flag.value = "hello world"
received = client.set_configuration_setting(set_flag)
assert isinstance(received, FeatureFlagConfigurationSetting)
client.delete_configuration_setting(set_flag)
@app_config_decorator
@recorded_by_proxy
def test_feature_flag_invalid_json_access_properties(self, appconfiguration_connection_string):
client = self.create_client(appconfiguration_connection_string)
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(key, enabled=True)
set_flag = client.set_configuration_setting(feature_flag)
set_flag.value = "hello world"
assert set_flag.enabled == None
assert set_flag.filters == None
client.delete_configuration_setting(feature_flag)
class TestAppConfigurationConsistencyUnitTest(AppConfigTestCase):
def test_feature_flag_set_value(self):
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(
key,
enabled=True,
filters=[
{
"name": FILTER_PERCENTAGE,
"parameters": {
"Value": 10,
"User": "user1"
}
}
]
)
feature_flag.value = json.dumps({
"conditions": {
"client_filters": []
},
"enabled": False
})
assert feature_flag.enabled == False
def test_feature_flag_set_enabled(self):
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(
key,
enabled=True,
filters=[
{
"name": FILTER_PERCENTAGE,
"parameters": {
"Value": 10,
"User": "user1"
}
}
]
)
feature_flag.enabled = False
temp = json.loads(feature_flag.value)
assert temp["enabled"] == False
def test_feature_flag_prefix(self):
key = self.get_resource_name("key")
feature_flag = FeatureFlagConfigurationSetting(key, enabled=True)
assert feature_flag.key.startswith(".appconfig.featureflag/")
|