Add rule not to parse cases where the org name matches the portfolio name

This commit is contained in:
zandercymatics 2025-01-06 13:51:40 -07:00
parent 822c8dde0f
commit 6d13f26ffb
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 28 additions and 0 deletions

View file

@ -926,6 +926,7 @@ These fields are: requested_suborganization, suborganization_city, suborganizati
This is done by pulling from organization_name, city, and state_territory. This is done by pulling from organization_name, city, and state_territory.
The script will only parse records with a portfolio but no suborganization attached to it. The script will only parse records with a portfolio but no suborganization attached to it.
Additionally, it will not parse records wherein the organization name matches the portfolio org name.
### Running on sandboxes ### Running on sandboxes

View file

@ -2,6 +2,7 @@ import logging
from django.core.management import BaseCommand from django.core.management import BaseCommand
from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors, TerminalHelper from registrar.management.commands.utility.terminal_helper import PopulateScriptTemplate, TerminalColors, TerminalHelper
from registrar.models import DomainRequest from registrar.models import DomainRequest
from django.db.models import F
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -16,6 +17,10 @@ class Command(BaseCommand, PopulateScriptTemplate):
fields_to_update = ["requested_suborganization", "suborganization_city", "suborganization_state_territory"] fields_to_update = ["requested_suborganization", "suborganization_city", "suborganization_state_territory"]
self.mass_update_records(DomainRequest, filter_conditions, fields_to_update) self.mass_update_records(DomainRequest, filter_conditions, fields_to_update)
def custom_filter(self, records):
"""Exclude domain requests that have the same org name as the portfolio"""
return records.exclude(organization_name=F("portfolio__organization_name"))
def update_record(self, record: DomainRequest): def update_record(self, record: DomainRequest):
"""Adds data to requested_suborganization, suborganization_city, and suborganization_state_territory.""" """Adds data to requested_suborganization, suborganization_city, and suborganization_state_territory."""
record.requested_suborganization = record.organization_name record.requested_suborganization = record.organization_name

View file

@ -1764,6 +1764,16 @@ class TestPopulateRequestedSuborg(MockEppLib):
sub_organization=self.suborg, sub_organization=self.suborg,
) )
# Create a request where org name matches portfolio name
self.matching_name_request = completed_domain_request(
name="matching.gov",
organization_name="Test Portfolio",
city="Boston",
state_territory="MA",
portfolio=self.portfolio,
user=self.user,
)
def tearDown(self): def tearDown(self):
super().tearDown() super().tearDown()
DomainRequest.objects.all().delete() DomainRequest.objects.all().delete()
@ -1804,3 +1814,15 @@ class TestPopulateRequestedSuborg(MockEppLib):
self.assertIsNone(self.existing_suborg_request.requested_suborganization) self.assertIsNone(self.existing_suborg_request.requested_suborganization)
self.assertIsNone(self.existing_suborg_request.suborganization_city) self.assertIsNone(self.existing_suborg_request.suborganization_city)
self.assertIsNone(self.existing_suborg_request.suborganization_state_territory) self.assertIsNone(self.existing_suborg_request.suborganization_state_territory)
@less_console_noise_decorator
def test_populate_requested_suborg_matching_name(self):
"""Tests that requests with matching org/portfolio names are skipped"""
self.run_populate_requested_suborg()
self.matching_name_request.refresh_from_db()
# Verify the request wasn't modified since org name matches portfolio name
self.assertIsNone(self.matching_name_request.requested_suborganization)
self.assertIsNone(self.matching_name_request.suborganization_city)
self.assertIsNone(self.matching_name_request.suborganization_state_territory)