@@ -30,6 +30,18 @@ def init_configuration_store(mocker, mock_schema: Dict, config: Config) -> Confi
30
30
return conf_store
31
31
32
32
33
+ def init_fetcher_side_effect (mocker , config : Config , side_effect ) -> AppConfigFetcher :
34
+ mocked_get_conf = mocker .patch ("aws_lambda_powertools.utilities.parameters.AppConfigProvider.get" )
35
+ mocked_get_conf .side_effect = side_effect
36
+ return AppConfigFetcher (
37
+ environment = "env" ,
38
+ service = "service" ,
39
+ configuration_name = "conf" ,
40
+ cache_seconds = 1 ,
41
+ config = config ,
42
+ )
43
+
44
+
33
45
# this test checks that we get correct value of feature that exists in the schema.
34
46
# we also don't send an empty rules_context dict in this case
35
47
def test_toggles_rule_does_not_match (mocker , config ):
@@ -424,17 +436,33 @@ def test_multiple_features_only_some_enabled(mocker, config):
424
436
assert enabled_list == expected_value
425
437
426
438
439
+ def test_get_feature_toggle_handles_error (mocker , config ):
440
+ # GIVEN a schema fetch that raises a ConfigurationError
441
+ schema_fetcher = init_fetcher_side_effect (mocker , config , GetParameterError ())
442
+ conf_store = ConfigurationStore (schema_fetcher )
443
+
444
+ # WHEN calling get_feature_toggle
445
+ toggle = conf_store .get_feature_toggle (feature_name = "Foo" , value_if_missing = False )
446
+
447
+ # THEN handle the error and return the value_if_missing
448
+ assert toggle is False
449
+
450
+
451
+ def test_get_all_enabled_feature_toggles_handles_error (mocker , config ):
452
+ # GIVEN a schema fetch that raises a ConfigurationError
453
+ schema_fetcher = init_fetcher_side_effect (mocker , config , GetParameterError ())
454
+ conf_store = ConfigurationStore (schema_fetcher )
455
+
456
+ # WHEN calling get_all_enabled_feature_toggles
457
+ toggles = conf_store .get_all_enabled_feature_toggles (rules_context = None )
458
+
459
+ # THEN handle the error and return an empty list
460
+ assert toggles == []
461
+
462
+
427
463
def test_app_config_get_parameter_err (mocker , config ):
428
464
# GIVEN an appconfig with a missing config
429
- mocked_get_conf = mocker .patch ("aws_lambda_powertools.utilities.parameters.AppConfigProvider.get" )
430
- mocked_get_conf .side_effect = GetParameterError ()
431
- app_conf_fetcher = AppConfigFetcher (
432
- environment = "env" ,
433
- service = "service" ,
434
- configuration_name = "conf" ,
435
- cache_seconds = 1 ,
436
- config = config ,
437
- )
465
+ app_conf_fetcher = init_fetcher_side_effect (mocker , config , GetParameterError ())
438
466
439
467
# WHEN calling get_json_configuration
440
468
with pytest .raises (ConfigurationError ) as err :
0 commit comments