-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add decrby to redis_client - Added a simple decorator for functions that are behind a feature flag * formatting * Fix code QL issues
- Loading branch information
Showing
6 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
docopt==0.6.2 | ||
Flask==2.3.3 | ||
markupsafe==2.1.4 | ||
git+https://github.com/cds-snc/[email protected].1#egg=notifications-utils | ||
git+https://github.com/cds-snc/[email protected].2#egg=notifications-utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from flask import current_app | ||
from functools import wraps | ||
|
||
|
||
def requires_feature(flag): | ||
def decorator_feature_flag(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
if current_app.config[flag]: | ||
return func(*args, **kwargs) | ||
return None | ||
|
||
return wrapper | ||
|
||
return decorator_feature_flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from notifications_utils.decorators import requires_feature | ||
|
||
|
||
@requires_feature("FEATURE_FLAG") | ||
def decorated_function(): | ||
return "Feature enabled" | ||
|
||
|
||
def test_requires_feature_enabled(mocker, app): | ||
app.config["FEATURE_FLAG"] = True | ||
result = decorated_function() | ||
assert result == "Feature enabled" | ||
|
||
|
||
def test_requires_feature_disabled(mocker, app): | ||
app.config["FEATURE_FLAG"] = False | ||
result = decorated_function() | ||
assert result is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters