Skip to content

Commit 382ac3a

Browse files
author
Ran Isenberg
committed
add extra test for not matching not_in
1 parent 5db73c2 commit 382ac3a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

aws_lambda_powertools/utilities/feature_flags/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class SchemaValidator(BaseValidator):
8080
The value MUST contain the following members:
8181
8282
* **action**: `str`. Operation to perform to match a key and value.
83-
The value MUST be either EQUALS, STARTSWITH, ENDSWITH, IN
83+
The value MUST be either EQUALS, STARTSWITH, ENDSWITH, IN, NOT_IN
8484
* **key**: `str`. Key in given context to perform operation
8585
* **value**: `Any`. Value in given context that should match action operation.
8686

tests/functional/feature_flags/test_feature_flags.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ def test_flags_no_match_rule_with_in_action(mocker, config):
310310
toggle = feature_flags.evaluate(name="my_feature", context={"tenant_id": "6", "username": "a"}, default=False)
311311
assert toggle == expected_value
312312

313+
313314
def test_flags_match_rule_with_not_in_action(mocker, config):
314315
expected_value = True
315316
mocked_app_config_schema = {
@@ -334,6 +335,29 @@ def test_flags_match_rule_with_not_in_action(mocker, config):
334335
assert toggle == expected_value
335336

336337

338+
def test_flags_no_match_rule_with_not_in_action(mocker, config):
339+
expected_value = False
340+
mocked_app_config_schema = {
341+
"my_feature": {
342+
"default": expected_value,
343+
"rules": {
344+
"tenant id is contained in [8, 2]": {
345+
"when_match": True,
346+
"conditions": [
347+
{
348+
"action": RuleAction.NOT_IN.value,
349+
"key": "tenant_id",
350+
"value": ["6", "4"],
351+
}
352+
],
353+
}
354+
},
355+
}
356+
}
357+
feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
358+
toggle = feature_flags.evaluate(name="my_feature", context={"tenant_id": "6", "username": "a"}, default=False)
359+
assert toggle == expected_value
360+
337361

338362
def test_multiple_features_enabled(mocker, config):
339363
expected_value = ["my_feature", "my_feature2"]

0 commit comments

Comments
 (0)