|
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 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 | +) |
10 | 19 | from aws_lambda_powertools.utilities.parameters import GetParameterError
|
11 | 20 |
|
12 | 21 |
|
@@ -461,3 +470,29 @@ def test_features_jmespath_envelope(mocker, config):
|
461 | 470 | feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config, envelope="features")
|
462 | 471 | toggle = feature_flags.evaluate(name="my_feature", context={}, default=False)
|
463 | 472 | 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