@@ -15,7 +15,7 @@ def config():
15
15
return Config (region_name = "us-east-1" )
16
16
17
17
18
- def init_configuration_store (mocker , mock_schema : Dict , config : Config ) -> FeatureFlags :
18
+ def init_feature_flags (mocker , mock_schema : Dict , config : Config ) -> FeatureFlags :
19
19
mocked_get_conf = mocker .patch ("aws_lambda_powertools.utilities.parameters.AppConfigProvider.get" )
20
20
mocked_get_conf .return_value = mock_schema
21
21
@@ -26,8 +26,8 @@ def init_configuration_store(mocker, mock_schema: Dict, config: Config) -> Featu
26
26
cache_seconds = 600 ,
27
27
config = config ,
28
28
)
29
- conf_store : FeatureFlags = FeatureFlags (store = app_conf_fetcher )
30
- return conf_store
29
+ feature_flags : FeatureFlags = FeatureFlags (store = app_conf_fetcher )
30
+ return feature_flags
31
31
32
32
33
33
def init_fetcher_side_effect (mocker , config : Config , side_effect ) -> AppConfigStore :
@@ -66,8 +66,8 @@ def test_toggles_rule_does_not_match(mocker, config):
66
66
}
67
67
}
68
68
69
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
70
- toggle = conf_store .evaluate (name = "my_feature" , context = {}, default = False )
69
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
70
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {}, default = False )
71
71
assert toggle == expected_value
72
72
73
73
@@ -77,8 +77,8 @@ def test_toggles_no_conditions_feature_does_not_exist(mocker, config):
77
77
expected_value = False
78
78
mocked_app_config_schema = {"features" : {"my_fake_feature" : {"default" : True }}}
79
79
80
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
81
- toggle = conf_store .evaluate (name = "my_feature" , context = {}, default = expected_value )
80
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
81
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {}, default = expected_value )
82
82
assert toggle == expected_value
83
83
84
84
@@ -87,8 +87,8 @@ def test_toggles_no_conditions_feature_does_not_exist(mocker, config):
87
87
def test_toggles_no_rules (mocker , config ):
88
88
expected_value = True
89
89
mocked_app_config_schema = {"features" : {"my_feature" : {"default" : expected_value }}}
90
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
91
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
90
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
91
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
92
92
assert toggle == expected_value
93
93
94
94
@@ -114,8 +114,8 @@ def test_toggles_conditions_no_match(mocker, config):
114
114
}
115
115
}
116
116
}
117
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
118
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
117
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
118
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
119
119
assert toggle == expected_value
120
120
121
121
@@ -148,8 +148,8 @@ def test_toggles_conditions_rule_match_equal_multiple_conditions(mocker, config)
148
148
}
149
149
},
150
150
}
151
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
152
- toggle = conf_store .evaluate (
151
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
152
+ toggle = feature_flags .evaluate (
153
153
name = "my_feature" ,
154
154
context = {
155
155
"tenant_id" : tenant_id_val ,
@@ -190,8 +190,8 @@ def test_toggles_conditions_no_rule_match_equal_multiple_conditions(mocker, conf
190
190
}
191
191
}
192
192
}
193
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
194
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
193
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
194
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
195
195
assert toggle == expected_val
196
196
197
197
@@ -246,18 +246,20 @@ def test_toggles_conditions_rule_match_multiple_actions_multiple_rules_multiple_
246
246
}
247
247
}
248
248
249
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
249
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
250
250
# match first rule
251
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "abcd" }, default = False )
251
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "abcd" }, default = False )
252
252
assert toggle == expected_value_first_check
253
253
# match second rule
254
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "4446" , "username" : "az" }, default = False )
254
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "4446" , "username" : "az" }, default = False )
255
255
assert toggle == expected_value_second_check
256
256
# match no rule
257
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "11114446" , "username" : "ab" }, default = False )
257
+ toggle = feature_flags .evaluate (
258
+ name = "my_feature" , context = {"tenant_id" : "11114446" , "username" : "ab" }, default = False
259
+ )
258
260
assert toggle == expected_value_third_check
259
261
# feature doesn't exist
260
- toggle = conf_store .evaluate (
262
+ toggle = feature_flags .evaluate (
261
263
name = "my_fake_feature" ,
262
264
context = {"tenant_id" : "11114446" , "username" : "ab" },
263
265
default = expected_value_fourth_case ,
@@ -287,8 +289,8 @@ def test_toggles_match_rule_with_contains_action(mocker, config):
287
289
}
288
290
}
289
291
}
290
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
291
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
292
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
293
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
292
294
assert toggle == expected_value
293
295
294
296
@@ -314,8 +316,8 @@ def test_toggles_no_match_rule_with_contains_action(mocker, config):
314
316
}
315
317
},
316
318
}
317
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
318
- toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
319
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
320
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
319
321
assert toggle == expected_value
320
322
321
323
@@ -346,8 +348,8 @@ def test_multiple_features_enabled(mocker, config):
346
348
},
347
349
}
348
350
}
349
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
350
- enabled_list : List [str ] = conf_store .get_enabled_features (context = {"tenant_id" : "6" , "username" : "a" })
351
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
352
+ enabled_list : List [str ] = feature_flags .get_enabled_features (context = {"tenant_id" : "6" , "username" : "a" })
351
353
assert enabled_list == expected_value
352
354
353
355
@@ -394,18 +396,18 @@ def test_multiple_features_only_some_enabled(mocker, config):
394
396
},
395
397
}
396
398
}
397
- conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
398
- enabled_list : List [str ] = conf_store .get_enabled_features (context = {"tenant_id" : "6" , "username" : "a" })
399
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
400
+ enabled_list : List [str ] = feature_flags .get_enabled_features (context = {"tenant_id" : "6" , "username" : "a" })
399
401
assert enabled_list == expected_value
400
402
401
403
402
404
def test_get_feature_toggle_handles_error (mocker , config ):
403
405
# GIVEN a schema fetch that raises a ConfigurationError
404
406
schema_fetcher = init_fetcher_side_effect (mocker , config , GetParameterError ())
405
- conf_store = FeatureFlags (schema_fetcher )
407
+ feature_flags = FeatureFlags (schema_fetcher )
406
408
407
409
# WHEN calling evaluate
408
- toggle = conf_store .evaluate (name = "Foo" , default = False )
410
+ toggle = feature_flags .evaluate (name = "Foo" , default = False )
409
411
410
412
# THEN handle the error and return the default
411
413
assert toggle is False
@@ -414,10 +416,10 @@ def test_get_feature_toggle_handles_error(mocker, config):
414
416
def test_get_all_enabled_feature_toggles_handles_error (mocker , config ):
415
417
# GIVEN a schema fetch that raises a ConfigurationError
416
418
schema_fetcher = init_fetcher_side_effect (mocker , config , GetParameterError ())
417
- conf_store = FeatureFlags (schema_fetcher )
419
+ feature_flags = FeatureFlags (schema_fetcher )
418
420
419
421
# WHEN calling get_enabled_features
420
- toggles = conf_store .get_enabled_features (context = None )
422
+ toggles = feature_flags .get_enabled_features (context = None )
421
423
422
424
# THEN handle the error and return an empty list
423
425
assert toggles == []
@@ -437,18 +439,18 @@ def test_app_config_get_parameter_err(mocker, config):
437
439
438
440
def test_match_by_action_no_matching_action (mocker , config ):
439
441
# GIVEN an unsupported action
440
- conf_store = init_configuration_store (mocker , {}, config )
442
+ feature_flags = init_feature_flags (mocker , {}, config )
441
443
# WHEN calling _match_by_action
442
- result = conf_store ._match_by_action ("Foo" , None , "foo" )
444
+ result = feature_flags ._match_by_action ("Foo" , None , "foo" )
443
445
# THEN default to False
444
446
assert result is False
445
447
446
448
447
449
def test_match_by_action_attribute_error (mocker , config ):
448
450
# GIVEN a startswith action and 2 integer
449
- conf_store = init_configuration_store (mocker , {}, config )
451
+ feature_flags = init_feature_flags (mocker , {}, config )
450
452
# WHEN calling _match_by_action
451
- result = conf_store ._match_by_action (RuleAction .STARTSWITH .value , 1 , 100 )
453
+ result = feature_flags ._match_by_action (RuleAction .STARTSWITH .value , 1 , 100 )
452
454
# THEN swallow the AttributeError and return False
453
455
assert result is False
454
456
@@ -457,10 +459,10 @@ def test_is_rule_matched_no_matches(mocker, config):
457
459
# GIVEN an empty list of conditions
458
460
rule = {schema .CONDITIONS_KEY : []}
459
461
rules_context = {}
460
- conf_store = init_configuration_store (mocker , {}, config )
462
+ feature_flags = init_feature_flags (mocker , {}, config )
461
463
462
464
# WHEN calling _is_rule_matched
463
- result = conf_store ._is_rule_matched (rule_name = "dummy" , feature_name = "dummy" , rule = rule , context = rules_context )
465
+ result = feature_flags ._is_rule_matched (rule_name = "dummy" , feature_name = "dummy" , rule = rule , context = rules_context )
464
466
465
467
# THEN return False
466
468
assert result is False
0 commit comments