Skip to content

Commit d8125c7

Browse files
committed
test: conditional dict values
1 parent e0ab7a1 commit d8125c7

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tests/functional/feature_toggles/test_feature_toggles.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
from aws_lambda_powertools.utilities.feature_flags import ConfigurationStoreError, schema
77
from aws_lambda_powertools.utilities.feature_flags.appconfig import AppConfigStore
88
from aws_lambda_powertools.utilities.feature_flags.feature_flags import FeatureFlags
9-
from aws_lambda_powertools.utilities.feature_flags.schema import RuleAction
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+
)
1019
from aws_lambda_powertools.utilities.parameters import GetParameterError
1120

1221

@@ -461,3 +470,29 @@ def test_features_jmespath_envelope(mocker, config):
461470
feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config, envelope="features")
462471
toggle = feature_flags.evaluate(name="my_feature", context={}, default=False)
463472
assert toggle == expected_value
473+
474+
475+
# test_match_rule_with_contains_action
476+
def test_match_condition_with_dict_value(mocker, config):
477+
expected_value = True
478+
mocked_app_config_schema = {
479+
"my_feature": {
480+
FEATURE_DEFAULT_VAL_KEY: False,
481+
RULES_KEY: {
482+
"tenant id is 6 and username is lessa": {
483+
RULE_MATCH_VALUE: expected_value,
484+
CONDITIONS_KEY: [
485+
{
486+
CONDITION_ACTION: RuleAction.EQUALS.value,
487+
CONDITION_KEY: "tenant",
488+
CONDITION_VALUE: {"tenant_id": "6", "username": "lessa"},
489+
}
490+
],
491+
}
492+
},
493+
}
494+
}
495+
feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
496+
ctx = {"tenant": {"tenant_id": "6", "username": "lessa"}}
497+
toggle = feature_flags.evaluate(name="my_feature", context=ctx, default=False)
498+
assert toggle == expected_value

0 commit comments

Comments
 (0)