-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(feature_flags): Added inequality conditions #721
Conversation
@heitorlessa -- conflicts resolved. |
Codecov Report
@@ Coverage Diff @@
## develop #721 +/- ##
========================================
Coverage 99.93% 99.93%
========================================
Files 116 116
Lines 4910 4914 +4
Branches 271 271
========================================
+ Hits 4907 4911 +4
Misses 1 1
Partials 2 2
Continue to review full report at Codecov.
|
@heitorlessa -- tests fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot again @gwlester - my only ask would be to merge these _1
and _2
tests so we reduce the number of imports that pytests have to make
def test_flags_less_than_no_match_1(mocker, config): | ||
expected_value = False | ||
mocked_app_config_schema = { | ||
"my_feature": { | ||
"default": expected_value, | ||
"rules": { | ||
"Date less than 2021.10.31": { | ||
"when_match": True, | ||
"conditions": [ | ||
{ | ||
"action": RuleAction.KEY_LESS_THAN_VALUE.value, | ||
"key": "current_date", | ||
"value": "2021.10.31", | ||
} | ||
], | ||
} | ||
}, | ||
} | ||
} | ||
feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config) | ||
toggle = feature_flags.evaluate(name="my_feature", context={"tenant_id": "345345435", "username": "a", "current_date": "2021.12.25"}, default=False) | ||
assert toggle == expected_value | ||
|
||
def test_flags_less_than_no_match_2(mocker, config): | ||
expected_value = False | ||
mocked_app_config_schema = { | ||
"my_feature": { | ||
"default": expected_value, | ||
"rules": { | ||
"Date less than 2021.10.31": { | ||
"when_match": True, | ||
"conditions": [ | ||
{ | ||
"action": RuleAction.KEY_LESS_THAN_VALUE.value, | ||
"key": "current_date", | ||
"value": "2021.10.31", | ||
} | ||
], | ||
} | ||
}, | ||
} | ||
} | ||
feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config) | ||
toggle = feature_flags.evaluate(name="my_feature", context={"tenant_id": "345345435", "username": "a", "current_date": "2021.10.31"}, default=False) | ||
assert toggle == expected_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps merge them in a single test w/ different features?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I always lean toward one test for one condition.
We were just bit by one test that was supposed to test several conditions and due to the complexity was not testing them but was still appearing to pass.
Fair enough
…On Sun, 3 Oct 2021 at 20:53, Gerald Leter ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In tests/functional/feature_flags/test_feature_flags.py
<#721 (comment)>
:
> +def test_flags_less_than_no_match_1(mocker, config):
+ expected_value = False
+ mocked_app_config_schema = {
+ "my_feature": {
+ "default": expected_value,
+ "rules": {
+ "Date less than 2021.10.31": {
+ "when_match": True,
+ "conditions": [
+ {
+ "action": RuleAction.KEY_LESS_THAN_VALUE.value,
+ "key": "current_date",
+ "value": "2021.10.31",
+ }
+ ],
+ }
+ },
+ }
+ }
+ feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
+ toggle = feature_flags.evaluate(name="my_feature", context={"tenant_id": "345345435", "username": "a", "current_date": "2021.12.25"}, default=False)
+ assert toggle == expected_value
+
+def test_flags_less_than_no_match_2(mocker, config):
+ expected_value = False
+ mocked_app_config_schema = {
+ "my_feature": {
+ "default": expected_value,
+ "rules": {
+ "Date less than 2021.10.31": {
+ "when_match": True,
+ "conditions": [
+ {
+ "action": RuleAction.KEY_LESS_THAN_VALUE.value,
+ "key": "current_date",
+ "value": "2021.10.31",
+ }
+ ],
+ }
+ },
+ }
+ }
+ feature_flags = init_feature_flags(mocker, mocked_app_config_schema, config)
+ toggle = feature_flags.evaluate(name="my_feature", context={"tenant_id": "345345435", "username": "a", "current_date": "2021.10.31"}, default=False)
+ assert toggle == expected_value
We could, but I always lean toward one test for one condition.
We were just bit by one test that was supposed to test several conditions
and due to the complexity was not testing them but was still appearing to
pass.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#721 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBA3EKDCE527BYXGCYLUFCRDRANCNFSM5FE3RTHA>
.
|
…tools-python into develop * 'develop' of https://github.com/awslabs/aws-lambda-powertools-python: feat(feature_flags): Added inequality conditions (aws-powertools#721) fix(feature-flags): rules should evaluate with an AND op (aws-powertools#724) fix(logger): push extra keys to the end (aws-powertools#722)
Issue #701, if available:
Description of changes:
Added inequality conditions.
Checklist
Breaking change checklist
RFC issue #701:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
View rendered docs/utilities/feature_flags.md