mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-03 08:22:18 +02:00
Cleanup part 2
This commit is contained in:
parent
9e49ca4eac
commit
8f3f7f14f2
4 changed files with 14 additions and 21 deletions
|
@ -275,17 +275,12 @@ class Command(BaseCommand):
|
|||
# Set suborg info
|
||||
domain_request.sub_organization = suborgs.get(domain_request.organization_name, None)
|
||||
if domain_request.sub_organization is None:
|
||||
clean_organization_name = None
|
||||
if isinstance(domain_request.organization_name, str):
|
||||
clean_organization_name = normalize_string(domain_request.organization_name, lowercase=False)
|
||||
|
||||
clean_city = None
|
||||
if isinstance(domain_request.city, str):
|
||||
clean_city = normalize_string(domain_request.city, lowercase=False)
|
||||
|
||||
domain_request.requested_suborganization = clean_organization_name
|
||||
domain_request.suborganization_city = clean_city
|
||||
domain_request.requested_suborganization = normalize_string(
|
||||
domain_request.organization_name, lowercase=False
|
||||
)
|
||||
domain_request.suborganization_city = normalize_string(domain_request.city, lowercase=False)
|
||||
domain_request.suborganization_state_territory = domain_request.state_territory
|
||||
|
||||
self.updated_portfolios.add(portfolio)
|
||||
|
||||
DomainRequest.objects.bulk_update(
|
||||
|
@ -322,8 +317,7 @@ class Command(BaseCommand):
|
|||
suborgs = Suborganization.objects.filter(portfolio=portfolio).in_bulk(field_name="name")
|
||||
for domain_info in domain_infos:
|
||||
domain_info.portfolio = portfolio
|
||||
if domain_info.organization_name in suborgs:
|
||||
domain_info.sub_organization = suborgs.get(domain_info.organization_name)
|
||||
domain_info.sub_organization = suborgs.get(domain_info.organization_name, None)
|
||||
|
||||
DomainInformation.objects.bulk_update(domain_infos, ["portfolio", "sub_organization"])
|
||||
message = f"Added portfolio '{portfolio}' to {len(domain_infos)} domains."
|
||||
|
|
|
@ -8,7 +8,7 @@ from django_fsm import FSMField, transition # type: ignore
|
|||
from django.utils import timezone
|
||||
from registrar.models.domain import Domain
|
||||
from registrar.models.federal_agency import FederalAgency
|
||||
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper, normalize_string
|
||||
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
|
||||
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
||||
from registrar.utility.constants import BranchChoices
|
||||
from auditlog.models import LogEntry
|
||||
|
|
|
@ -347,5 +347,9 @@ def value_of_attribute(obj, attribute_name: str):
|
|||
|
||||
def normalize_string(string_to_normalize: str, lowercase=True) -> str:
|
||||
"""Normalizes a given string. Returns a string without extra spaces, in all lowercase."""
|
||||
if not isinstance(string_to_normalize, str):
|
||||
logger.error(f"normalize_string => {string_to_normalize} is not type str.")
|
||||
return string_to_normalize
|
||||
|
||||
new_string = " ".join(string_to_normalize.split())
|
||||
return new_string.lower() if lowercase else new_string
|
||||
|
|
|
@ -1521,10 +1521,7 @@ class TestCreateFederalPortfolio(TestCase):
|
|||
def test_handle_portfolio_requests_sync_federal_agency(self):
|
||||
"""Test that federal agency is cleared when org name matches portfolio name"""
|
||||
# Create a portfolio. This script skips over "started"
|
||||
portfolio = Portfolio.objects.create(
|
||||
organization_name="Sugarcane",
|
||||
creator=self.user
|
||||
)
|
||||
portfolio = Portfolio.objects.create(organization_name="Sugarcane", creator=self.user)
|
||||
# Create a domain request with matching org name
|
||||
matching_request = completed_domain_request(
|
||||
name="matching.gov",
|
||||
|
@ -1532,7 +1529,7 @@ class TestCreateFederalPortfolio(TestCase):
|
|||
generic_org_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||
federal_agency=self.federal_agency_2,
|
||||
user=self.user,
|
||||
portfolio=portfolio
|
||||
portfolio=portfolio,
|
||||
)
|
||||
|
||||
# Create a request not in started (no change should occur)
|
||||
|
@ -1545,9 +1542,7 @@ class TestCreateFederalPortfolio(TestCase):
|
|||
)
|
||||
|
||||
self.run_create_federal_portfolio(agency_name="Sugarcane", parse_requests=True)
|
||||
self.run_create_federal_portfolio(
|
||||
agency_name="Test Federal Agency", parse_requests=True
|
||||
)
|
||||
self.run_create_federal_portfolio(agency_name="Test Federal Agency", parse_requests=True)
|
||||
|
||||
# Refresh from db
|
||||
matching_request.refresh_from_db()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue