lint and fix test

This commit is contained in:
zandercymatics 2025-01-28 09:58:41 -07:00
parent 8504eb1f39
commit ad79557a55
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 23 additions and 32 deletions

View file

@ -367,7 +367,7 @@ class OrganizationContactForm(RegistrarForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# 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.
federal_agency_queryset = FederalAgency.objects.exclude(agency__in=self.excluded_agencies) federal_agency_queryset = FederalAgency.objects.exclude(agency__in=self.excluded_agencies)
@ -376,7 +376,7 @@ class OrganizationContactForm(RegistrarForm):
federal_agency_queryset = federal_agency_queryset.exclude( federal_agency_queryset = federal_agency_queryset.exclude(
agency__in=Portfolio.objects.values_list("organization_name", flat=True) agency__in=Portfolio.objects.values_list("organization_name", flat=True)
) )
self.fields["federal_agency"].queryset = federal_agency_queryset self.fields["federal_agency"].queryset = federal_agency_queryset
def clean_federal_agency(self): def clean_federal_agency(self):

View file

@ -244,7 +244,6 @@ class Domain(TimeStampedModel, DomainHelper):
is called in the validate function on the request/domain page is called in the validate function on the request/domain page
throws- RegistryError or InvalidDomainError""" throws- RegistryError or InvalidDomainError"""
return True
if not cls.string_could_be_domain(domain): if not cls.string_could_be_domain(domain):
logger.warning("Not a valid domain: %s" % str(domain)) logger.warning("Not a valid domain: %s" % str(domain))
# throw invalid domain error so that it can be caught in # throw invalid domain error so that it can be caught in

View file

@ -1293,9 +1293,13 @@ class DomainRequest(TimeStampedModel):
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"):
# Check if the current federal agency is an outlawed one # Check if the current federal agency is an outlawed one
Portfolio = apps.get_model("registrar.Portfolio") Portfolio = apps.get_model("registrar.Portfolio")
return FederalAgency.objects.exclude( return (
agency__in=Portfolio.objects.values_list("organization_name", flat=True), FederalAgency.objects.exclude(
).filter(agency=self.federal_agency).exists() agency__in=Portfolio.objects.values_list("organization_name", flat=True),
)
.filter(agency=self.federal_agency)
.exists()
)
# NOTE: Shouldn't this be an AND on all required fields? # NOTE: Shouldn't this be an AND on all required fields?
return ( return (

View file

@ -28,29 +28,29 @@ class TestFlagIsActiveAnywhere(TestCase):
def setUp(self): def setUp(self):
self.user = User.objects.create_user(username="testuser") self.user = User.objects.create_user(username="testuser")
self.flag_name = "test_flag" self.flag_name = "test_flag"
@override_flag("test_flag", active=True) @override_flag("test_flag", active=True)
def test_flag_active_for_everyone(self): def test_flag_active_for_everyone(self):
"""Test when flag is active for everyone""" """Test when flag is active for everyone"""
is_active = flag_is_active_anywhere("test_flag") is_active = flag_is_active_anywhere("test_flag")
self.assertTrue(is_active) self.assertTrue(is_active)
@override_flag("test_flag", active=False) @override_flag("test_flag", active=False)
def test_flag_inactive_for_everyone(self): def test_flag_inactive_for_everyone(self):
"""Test when flag is inactive for everyone""" """Test when flag is inactive for everyone"""
is_active = flag_is_active_anywhere("test_flag") is_active = flag_is_active_anywhere("test_flag")
self.assertFalse(is_active) self.assertFalse(is_active)
def test_flag_active_for_some_users(self): def test_flag_active_for_some_users(self):
"""Test when flag is active for specific users""" """Test when flag is active for specific users"""
flag, _ = get_waffle_flag_model().objects.get_or_create(name="test_flag") flag, _ = get_waffle_flag_model().objects.get_or_create(name="test_flag")
flag.everyone = None flag.everyone = None
flag.save() flag.save()
flag.users.add(self.user) flag.users.add(self.user)
is_active = flag_is_active_anywhere("test_flag") is_active = flag_is_active_anywhere("test_flag")
self.assertTrue(is_active) self.assertTrue(is_active)
def test_flag_inactive_with_no_users(self): def test_flag_inactive_with_no_users(self):
"""Test when flag has no users and everyone is None""" """Test when flag has no users and everyone is None"""
flag, _ = get_waffle_flag_model().objects.get_or_create(name="test_flag") flag, _ = get_waffle_flag_model().objects.get_or_create(name="test_flag")

View file

@ -3228,18 +3228,12 @@ class TestDomainRequestWizard(TestWithUser, WebTest):
"""Tests unlock_organization_contact when agency exists in a portfolio""" """Tests unlock_organization_contact when agency exists in a portfolio"""
# Create a federal agency # Create a federal agency
federal_agency = FederalAgency.objects.create(agency="Portfolio Agency") federal_agency = FederalAgency.objects.create(agency="Portfolio Agency")
# Create a portfolio with matching organization name # Create a portfolio with matching organization name
Portfolio.objects.create( Portfolio.objects.create(creator=self.user, organization_name=federal_agency.agency)
creator=self.user,
organization_name=federal_agency.agency
)
# Create domain request with the portfolio agency # Create domain request with the portfolio agency
domain_request = completed_domain_request( domain_request = completed_domain_request(federal_agency=federal_agency, user=self.user)
federal_agency=federal_agency,
user=self.user
)
self.assertFalse(domain_request.unlock_organization_contact()) self.assertFalse(domain_request.unlock_organization_contact())
@override_flag("organization_feature", active=False) @override_flag("organization_feature", active=False)
@ -3247,19 +3241,13 @@ class TestDomainRequestWizard(TestWithUser, WebTest):
@less_console_noise_decorator @less_console_noise_decorator
def test_unlock_organization_contact_flags_disabled(self): def test_unlock_organization_contact_flags_disabled(self):
"""Tests unlock_organization_contact when organization flags are disabled""" """Tests unlock_organization_contact when organization flags are disabled"""
# Create a federal agency # Create a federal agency
federal_agency = FederalAgency.objects.create(agency="Portfolio Agency") federal_agency = FederalAgency.objects.create(agency="Portfolio Agency")
# Create a portfolio with matching organization name
Portfolio.objects.create(
creator=self.user,
organization_name=federal_agency.agency
)
domain_request = completed_domain_request( # Create a portfolio with matching organization name
federal_agency=federal_agency, Portfolio.objects.create(creator=self.user, organization_name=federal_agency.agency)
user=self.user
) domain_request = completed_domain_request(federal_agency=federal_agency, user=self.user)
self.assertTrue(domain_request.unlock_organization_contact()) self.assertTrue(domain_request.unlock_organization_contact())