-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2834 from cisagov/backup/2647-waffle-flag-refactor
#2647: Small waffle flag refactor
- Loading branch information
Showing
5 changed files
with
43 additions
and
18 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
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,23 @@ | ||
from django.test import TestCase | ||
from registrar.models import User | ||
from waffle.testutils import override_flag | ||
from registrar.utility.waffle import flag_is_active_for_user | ||
|
||
|
||
class FlagIsActiveForUserTest(TestCase): | ||
|
||
def setUp(self): | ||
# Set up a test user | ||
self.user = User.objects.create_user(username="testuser") | ||
|
||
@override_flag("test_flag", active=True) | ||
def test_flag_active_for_user(self): | ||
# Test that the flag is active for the user | ||
is_active = flag_is_active_for_user(self.user, "test_flag") | ||
self.assertTrue(is_active) | ||
|
||
@override_flag("test_flag", active=False) | ||
def test_flag_inactive_for_user(self): | ||
# Test that the flag is inactive for the user | ||
is_active = flag_is_active_for_user(self.user, "test_flag") | ||
self.assertFalse(is_active) |
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,12 @@ | ||
from django.http import HttpRequest | ||
from waffle.decorators import flag_is_active | ||
|
||
|
||
def flag_is_active_for_user(user, flag_name): | ||
"""flag_is_active_for_user can be used when a waffle_flag may be | ||
activated for a user, but the context of where the flag needs to | ||
be tested does not have a request object available. | ||
When the request is available, flag_is_active should be used.""" | ||
request = HttpRequest() | ||
request.user = user | ||
return flag_is_active(request, flag_name) |