Skip to content

Commit b9571f3

Browse files
author
Ran Isenberg
committed
formatting fix
1 parent a21081d commit b9571f3

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

aws_lambda_powertools/utilities/feature_toggles/configuration_store.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def __init__(
4848
self._conf_name = conf_name
4949
self._conf_store = AppConfigProvider(environment=environment, application=service, config=config)
5050

51-
def _validate_json_schema(self, schema: str) -> bool:
52-
## todo
51+
def _validate_json_schema(self, schema: Dict[str, Any]) -> bool:
52+
#
5353
return True
5454

5555
def _match_by_action(self, action: str, restriction_value: Any, context_value: Any) -> bool:
@@ -138,27 +138,28 @@ def get_feature_toggle(self, *, feature_name: str, rules_context: Dict[str, Any]
138138
feature_name (str): feature name that you wish to fetch
139139
rules_context (Dict[str, Any]): dict of attributes that you would like to match the rules
140140
against, can be {'tenant_id: 'X', 'username':' 'Y', 'region': 'Z'} etc.
141-
value_if_missing (bool): this will be the returned value in case the feature toggle doesn't exist in the schema
142-
or there has been an error while fetching the configuration from appconfig
141+
value_if_missing (bool): this will be the returned value in case the feature toggle doesn't exist in
142+
the schema or there has been an error while fetching the
143+
configuration from appconfig
143144
144145
Returns:
145146
bool: calculated feature toggle value. several possibilities:
146147
1. if the feature doesn't appear in the schema or there has been an error fetching the
147-
configuration -> warning log would appear and value_if_missing is returned
148+
configuration -> error/warning log would appear and value_if_missing is returned
148149
2. feature exists and has no rules or no rules have matched -> return feature_default_value of
149150
the defined feature
150151
3. feature exists and a rule matches -> rule_default_value of rule is returned
151152
"""
152153
try:
153154
toggles_dict: Dict[str, Any] = self.get_configuration()
154155
except ConfigurationException:
155-
logger.warning("unable to get feature toggles JSON, returning provided default value")
156-
return default_value
156+
logger.error("unable to get feature toggles JSON, returning provided value_if_missing value") # noqa: E501
157+
return value_if_missing
157158

158159
feature: Dict[str, Dict] = toggles_dict.get(FEATURES_KEY, {}).get(feature_name, None)
159160
if feature is None:
160161
logger.warning(
161-
f"feature does not appear in configuration, using provided default value, feature_name={feature_name}, value_if_missing={value_if_missing}" # noqa: E501
162+
f"feature does not appear in configuration, using provided value_if_missing, feature_name={feature_name}, value_if_missing={value_if_missing}" # noqa: E501
162163
)
163164
return value_if_missing
164165

@@ -175,5 +176,8 @@ def get_feature_toggle(self, *, feature_name: str, rules_context: Dict[str, Any]
175176
f"looking for rule match, feature_name={feature_name}, feature_default_value={feature_default_value}"
176177
) # noqa: E501
177178
return self._handle_rules(
178-
feature_name=feature_name, rules_context=rules_context, feature_default_value=feature_default_value, rules=rules_list
179+
feature_name=feature_name,
180+
rules_context=rules_context,
181+
feature_default_value=feature_default_value,
182+
rules=rules_list,
179183
)

tests/functional/feature_toggles/test_feature_toggles.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def init_configuration_store(mocker, mock_schema: Dict, config: Config) -> Confi
2929
def test_toggles_rule_does_not_match(mocker, config):
3030
expected_value = "True"
3131
mocked_app_config_schema = {
32-
"log_level": "DEBUG",
3332
"features": {
3433
"my_feature": {
3534
"feature_default_value": expected_value,
@@ -59,7 +58,7 @@ def test_toggles_rule_does_not_match(mocker, config):
5958
# you get the default value of False that was sent to the get_feature_toggle API
6059
def test_toggles_no_restrictions_feature_does_not_exist(mocker, config):
6160
expected_value = False
62-
mocked_app_config_schema = {"log_level": "DEBUG", "features": {"my_fake_feature": {"feature_default_value": "True"}}}
61+
mocked_app_config_schema = {"features": {"my_fake_feature": {"feature_default_value": "True"}}}
6362

6463
conf_store = init_configuration_store(mocker, mocked_app_config_schema, config)
6564
toggle = conf_store.get_feature_toggle(feature_name="my_feature", rules_context={}, value_if_missing=expected_value)
@@ -70,7 +69,7 @@ def test_toggles_no_restrictions_feature_does_not_exist(mocker, config):
7069
# default value is False but the feature has a True default_value.
7170
def test_toggles_no_rules(mocker, config):
7271
expected_value = "True"
73-
mocked_app_config_schema = {"log_level": "DEBUG", "features": {"my_feature": {"feature_default_value": expected_value}}}
72+
mocked_app_config_schema = {"features": {"my_feature": {"feature_default_value": expected_value}}}
7473
conf_store = init_configuration_store(mocker, mocked_app_config_schema, config)
7574
toggle = conf_store.get_feature_toggle(
7675
feature_name="my_feature", rules_context={"tenant_id": "6", "username": "a"}, value_if_missing=False
@@ -82,7 +81,6 @@ def test_toggles_no_rules(mocker, config):
8281
def test_toggles_restrictions_no_match(mocker, config):
8382
expected_value = "True"
8483
mocked_app_config_schema = {
85-
"log_level": "DEBUG",
8684
"features": {
8785
"my_feature": {
8886
"feature_default_value": expected_value,
@@ -117,7 +115,6 @@ def test_toggles_restrictions_rule_match_equal_multiple_restrictions(mocker, con
117115
tenant_id_val = "6"
118116
username_val = "a"
119117
mocked_app_config_schema = {
120-
"log_level": "DEBUG",
121118
"features": {
122119
"my_feature": {
123120
"feature_default_value": "True",
@@ -160,7 +157,6 @@ def test_toggles_restrictions_rule_match_equal_multiple_restrictions(mocker, con
160157
def test_toggles_restrictions_no_rule_match_equal_multiple_restrictions(mocker, config):
161158
expected_val = "True"
162159
mocked_app_config_schema = {
163-
"log_level": "DEBUG",
164160
"features": {
165161
"my_feature": {
166162
"feature_default_value": expected_val,
@@ -199,7 +195,6 @@ def test_toggles_restrictions_rule_match_multiple_actions_multiple_rules_multipl
199195
expected_value_third_check = "False"
200196
expected_value_fourth_case = False
201197
mocked_app_config_schema = {
202-
"log_level": "DEBUG",
203198
"features": {
204199
"my_feature": {
205200
"feature_default_value": expected_value_third_check,
@@ -281,7 +276,6 @@ def test_toggles_restrictions_rule_match_multiple_actions_multiple_rules_multipl
281276
def test_toggles_match_rule_with_contains_action(mocker, config):
282277
expected_value = True
283278
mocked_app_config_schema = {
284-
"log_level": "DEBUG",
285279
"features": {
286280
"my_feature": {
287281
"feature_default_value": expected_value,
@@ -313,7 +307,6 @@ def test_toggles_match_rule_with_contains_action(mocker, config):
313307
def test_toggles_no_match_rule_with_contains_action(mocker, config):
314308
expected_value = False
315309
mocked_app_config_schema = {
316-
"log_level": "DEBUG",
317310
"features": {
318311
"my_feature": {
319312
"feature_default_value": expected_value,

0 commit comments

Comments
 (0)