mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-31 15:06:32 +02:00
Add unit test for waffle utility
This commit is contained in:
parent
297029a447
commit
1f9efb7fc0
2 changed files with 40 additions and 2 deletions
|
@ -322,6 +322,7 @@ class OrganizationContactForm(RegistrarForm):
|
||||||
# if it has been filled in when required.
|
# if it has been filled in when required.
|
||||||
# uncomment to see if modelChoiceField can be an arg later
|
# uncomment to see if modelChoiceField can be an arg later
|
||||||
required=False,
|
required=False,
|
||||||
|
# We populate this queryset in init. We want to exclude agencies with a portfolio.
|
||||||
queryset=FederalAgency.objects.none(),
|
queryset=FederalAgency.objects.none(),
|
||||||
widget=ComboboxWidget,
|
widget=ComboboxWidget,
|
||||||
)
|
)
|
||||||
|
@ -369,7 +370,6 @@ class OrganizationContactForm(RegistrarForm):
|
||||||
|
|
||||||
# Set the queryset for federal agency.
|
# Set the queryset for federal agency.
|
||||||
# If the organization_requests flag is active, we hide data that exists in portfolios.
|
# If the organization_requests flag is active, we hide data that exists in portfolios.
|
||||||
# NOTE: This function assumes that the federal_agency field was first set to None if a portfolio exists.
|
|
||||||
federal_agency_queryset = FederalAgency.objects.exclude(agency__in=self.excluded_agencies)
|
federal_agency_queryset = FederalAgency.objects.exclude(agency__in=self.excluded_agencies)
|
||||||
if flag_is_active_anywhere("organization_feature") and flag_is_active_anywhere("organization_requests"):
|
if flag_is_active_anywhere("organization_feature") and flag_is_active_anywhere("organization_requests"):
|
||||||
# Exclude both predefined agencies and those matching portfolio names in one query
|
# Exclude both predefined agencies and those matching portfolio names in one query
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from registrar.models import User
|
from registrar.models import User
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
from registrar.utility.waffle import flag_is_active_for_user
|
from waffle.models import get_waffle_flag_model
|
||||||
|
from registrar.utility.waffle import flag_is_active_for_user, flag_is_active_anywhere
|
||||||
|
|
||||||
|
|
||||||
class FlagIsActiveForUserTest(TestCase):
|
class FlagIsActiveForUserTest(TestCase):
|
||||||
|
@ -21,3 +22,40 @@ class FlagIsActiveForUserTest(TestCase):
|
||||||
# Test that the flag is inactive for the user
|
# Test that the flag is inactive for the user
|
||||||
is_active = flag_is_active_for_user(self.user, "test_flag")
|
is_active = flag_is_active_for_user(self.user, "test_flag")
|
||||||
self.assertFalse(is_active)
|
self.assertFalse(is_active)
|
||||||
|
|
||||||
|
|
||||||
|
class TestFlagIsActiveAnywhere(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.user = User.objects.create_user(username="testuser")
|
||||||
|
self.flag_name = "test_flag"
|
||||||
|
|
||||||
|
@override_flag("test_flag", active=True)
|
||||||
|
def test_flag_active_for_everyone(self):
|
||||||
|
"""Test when flag is active for everyone"""
|
||||||
|
is_active = flag_is_active_anywhere("test_flag")
|
||||||
|
self.assertTrue(is_active)
|
||||||
|
|
||||||
|
@override_flag("test_flag", active=False)
|
||||||
|
def test_flag_inactive_for_everyone(self):
|
||||||
|
"""Test when flag is inactive for everyone"""
|
||||||
|
is_active = flag_is_active_anywhere("test_flag")
|
||||||
|
self.assertFalse(is_active)
|
||||||
|
|
||||||
|
def test_flag_active_for_some_users(self):
|
||||||
|
"""Test when flag is active for specific users"""
|
||||||
|
flag, _ = get_waffle_flag_model().objects.get_or_create(name="test_flag")
|
||||||
|
flag.everyone = None
|
||||||
|
flag.save()
|
||||||
|
flag.users.add(self.user)
|
||||||
|
|
||||||
|
is_active = flag_is_active_anywhere("test_flag")
|
||||||
|
self.assertTrue(is_active)
|
||||||
|
|
||||||
|
def test_flag_inactive_with_no_users(self):
|
||||||
|
"""Test when flag has no users and everyone is None"""
|
||||||
|
flag, _ = get_waffle_flag_model().objects.get_or_create(name="test_flag")
|
||||||
|
flag.everyone = None
|
||||||
|
flag.save()
|
||||||
|
|
||||||
|
is_active = flag_is_active_anywhere("test_flag")
|
||||||
|
self.assertFalse(is_active)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue