Skip to content
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

Merged
merged 8 commits into from
Oct 3, 2021

Conversation

gwlester
Copy link
Contributor

@gwlester gwlester commented Oct 1, 2021

Issue #701, if available:

Description of changes:

Added inequality conditions.

Checklist

Breaking change checklist

RFC issue #701:

  • Migration process documented
  • Implement warnings (if it can live side by side)

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

@boring-cyborg boring-cyborg bot added area/utilities documentation Improvements or additions to documentation tests labels Oct 1, 2021
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 1, 2021
@gwlester
Copy link
Contributor Author

gwlester commented Oct 1, 2021

@heitorlessa -- conflicts resolved.

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2021

Codecov Report

Merging #721 (610b907) into develop (610f569) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
...owertools/utilities/feature_flags/feature_flags.py 100.00% <ø> (ø)
...ambda_powertools/utilities/feature_flags/schema.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 610f569...610b907. Read the comment docs.

@gwlester
Copy link
Contributor Author

gwlester commented Oct 1, 2021

@heitorlessa -- tests fixed.

Copy link
Contributor

@heitorlessa heitorlessa left a 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

tests/functional/feature_flags/test_feature_flags.py Outdated Show resolved Hide resolved
tests/functional/feature_flags/test_feature_flags.py Outdated Show resolved Hide resolved
Comment on lines +859 to +903
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@heitorlessa
Copy link
Contributor

heitorlessa commented Oct 3, 2021 via email

@heitorlessa heitorlessa added feature New feature or functionality area/feature_flags labels Oct 3, 2021
@heitorlessa heitorlessa merged commit 922ecf2 into aws-powertools:develop Oct 3, 2021
heitorlessa added a commit to heitorlessa/aws-lambda-powertools-python that referenced this pull request Oct 5, 2021
…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)
@heitorlessa heitorlessa removed the documentation Improvements or additions to documentation label Oct 5, 2021
@gwlester gwlester deleted the feature-701 branch January 31, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants