6
6
from aws_lambda_powertools .utilities .feature_flags import ConfigurationStoreError , schema
7
7
from aws_lambda_powertools .utilities .feature_flags .appconfig import AppConfigStore
8
8
from aws_lambda_powertools .utilities .feature_flags .feature_flags import FeatureFlags
9
- from aws_lambda_powertools .utilities .feature_flags .schema import (
10
- CONDITION_ACTION ,
11
- CONDITION_KEY ,
12
- CONDITION_VALUE ,
13
- CONDITIONS_KEY ,
14
- FEATURE_DEFAULT_VAL_KEY ,
15
- RULE_MATCH_VALUE ,
16
- RULES_KEY ,
17
- RuleAction ,
18
- )
9
+ from aws_lambda_powertools .utilities .feature_flags .schema import RuleAction
19
10
from aws_lambda_powertools .utilities .parameters import GetParameterError
20
11
21
12
@@ -57,7 +48,7 @@ def init_fetcher_side_effect(mocker, config: Config, side_effect) -> AppConfigSt
57
48
58
49
# this test checks that we get correct value of feature that exists in the schema.
59
50
# we also don't send an empty context dict in this case
60
- def test_toggles_rule_does_not_match (mocker , config ):
51
+ def test_flags_rule_does_not_match (mocker , config ):
61
52
expected_value = True
62
53
mocked_app_config_schema = {
63
54
"my_feature" : {
@@ -84,7 +75,7 @@ def test_toggles_rule_does_not_match(mocker, config):
84
75
85
76
# this test checks that if you try to get a feature that doesn't exist in the schema,
86
77
# you get the default value of False that was sent to the evaluate API
87
- def test_toggles_no_conditions_feature_does_not_exist (mocker , config ):
78
+ def test_flags_no_conditions_feature_does_not_exist (mocker , config ):
88
79
expected_value = False
89
80
mocked_app_config_schema = {"my_fake_feature" : {"default" : True }}
90
81
@@ -95,7 +86,7 @@ def test_toggles_no_conditions_feature_does_not_exist(mocker, config):
95
86
96
87
# check that feature match works when they are no rules and we send context.
97
88
# default value is False but the feature has a True default_value.
98
- def test_toggles_no_rules (mocker , config ):
89
+ def test_flags_no_rules (mocker , config ):
99
90
expected_value = True
100
91
mocked_app_config_schema = {"my_feature" : {"default" : expected_value }}
101
92
feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
@@ -104,7 +95,7 @@ def test_toggles_no_rules(mocker, config):
104
95
105
96
106
97
# check a case where the feature exists but the rule doesn't match so we revert to the default value of the feature
107
- def test_toggles_conditions_no_match (mocker , config ):
98
+ def test_flags_conditions_no_match (mocker , config ):
108
99
expected_value = True
109
100
mocked_app_config_schema = {
110
101
"my_feature" : {
@@ -129,7 +120,7 @@ def test_toggles_conditions_no_match(mocker, config):
129
120
130
121
131
122
# check that a rule can match when it has multiple conditions, see rule name for further explanation
132
- def test_toggles_conditions_rule_match_equal_multiple_conditions (mocker , config ):
123
+ def test_flags_conditions_rule_match_equal_multiple_conditions (mocker , config ):
133
124
expected_value = False
134
125
tenant_id_val = "6"
135
126
username_val = "a"
@@ -170,7 +161,7 @@ def test_toggles_conditions_rule_match_equal_multiple_conditions(mocker, config)
170
161
# check a case when rule doesn't match and it has multiple conditions,
171
162
# different tenant id causes the rule to not match.
172
163
# default value of the feature in this case is True
173
- def test_toggles_conditions_no_rule_match_equal_multiple_conditions (mocker , config ):
164
+ def test_flags_conditions_no_rule_match_equal_multiple_conditions (mocker , config ):
174
165
expected_val = True
175
166
mocked_app_config_schema = {
176
167
"my_feature" : {
@@ -201,7 +192,7 @@ def test_toggles_conditions_no_rule_match_equal_multiple_conditions(mocker, conf
201
192
202
193
203
194
# check rule match for multiple of action types
204
- def test_toggles_conditions_rule_match_multiple_actions_multiple_rules_multiple_conditions (mocker , config ):
195
+ def test_flags_conditions_rule_match_multiple_actions_multiple_rules_multiple_conditions (mocker , config ):
205
196
expected_value_first_check = True
206
197
expected_value_second_check = False
207
198
expected_value_third_check = False
@@ -271,7 +262,7 @@ def test_toggles_conditions_rule_match_multiple_actions_multiple_rules_multiple_
271
262
272
263
273
264
# check a case where the feature exists but the rule doesn't match so we revert to the default value of the feature
274
- def test_toggles_match_rule_with_contains_action (mocker , config ):
265
+ def test_flags_match_rule_with_contains_action (mocker , config ):
275
266
expected_value = True
276
267
mocked_app_config_schema = {
277
268
"my_feature" : {
@@ -295,7 +286,7 @@ def test_toggles_match_rule_with_contains_action(mocker, config):
295
286
assert toggle == expected_value
296
287
297
288
298
- def test_toggles_no_match_rule_with_contains_action (mocker , config ):
289
+ def test_flags_no_match_rule_with_contains_action (mocker , config ):
299
290
expected_value = False
300
291
mocked_app_config_schema = {
301
292
"my_feature" : {
@@ -407,16 +398,16 @@ def test_get_feature_toggle_handles_error(mocker, config):
407
398
assert toggle is False
408
399
409
400
410
- def test_get_all_enabled_feature_toggles_handles_error (mocker , config ):
401
+ def test_get_all_enabled_feature_flags_handles_error (mocker , config ):
411
402
# GIVEN a schema fetch that raises a ConfigurationStoreError
412
403
schema_fetcher = init_fetcher_side_effect (mocker , config , GetParameterError ())
413
404
feature_flags = FeatureFlags (schema_fetcher )
414
405
415
406
# WHEN calling get_enabled_features
416
- toggles = feature_flags .get_enabled_features (context = None )
407
+ flags = feature_flags .get_enabled_features (context = None )
417
408
418
409
# THEN handle the error and return an empty list
419
- assert toggles == []
410
+ assert flags == []
420
411
421
412
422
413
def test_app_config_get_parameter_err (mocker , config ):
@@ -477,15 +468,15 @@ def test_match_condition_with_dict_value(mocker, config):
477
468
expected_value = True
478
469
mocked_app_config_schema = {
479
470
"my_feature" : {
480
- FEATURE_DEFAULT_VAL_KEY : False ,
481
- RULES_KEY : {
471
+ "default" : False ,
472
+ "rules" : {
482
473
"tenant id is 6 and username is lessa" : {
483
- RULE_MATCH_VALUE : expected_value ,
484
- CONDITIONS_KEY : [
474
+ "when_match" : expected_value ,
475
+ "conditions" : [
485
476
{
486
- CONDITION_ACTION : RuleAction .EQUALS .value ,
487
- CONDITION_KEY : "tenant" ,
488
- CONDITION_VALUE : {"tenant_id" : "6" , "username" : "lessa" },
477
+ "action" : RuleAction .EQUALS .value ,
478
+ "key" : "tenant" ,
479
+ "value" : {"tenant_id" : "6" , "username" : "lessa" },
489
480
}
490
481
],
491
482
}
0 commit comments