From b3b415b56347f5f8f8fa693ef9ca4320912f2190 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 30 Aug 2024 08:40:04 -0600 Subject: [PATCH] Remove logic for location information --- .../commands/create_federal_portfolio.py | 40 +++++-------------- src/registrar/tests/common.py | 4 -- .../tests/test_management_scripts.py | 18 ++++----- 3 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/registrar/management/commands/create_federal_portfolio.py b/src/registrar/management/commands/create_federal_portfolio.py index bf4297705..219044fc5 100644 --- a/src/registrar/management/commands/create_federal_portfolio.py +++ b/src/registrar/management/commands/create_federal_portfolio.py @@ -98,6 +98,7 @@ class Command(BaseCommand): # Update everything else for key, value in portfolio_args.items(): setattr(portfolio, key, value) + portfolio.save() message = f"Modified portfolio '{portfolio}'" TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message) @@ -126,11 +127,13 @@ class Command(BaseCommand): new_suborgs = [] for name in org_names - set(existing_suborgs.values_list("name", flat=True)): if name.lower() == portfolio.organization_name.lower(): - # If the suborg name is a portfolio name that currently exists, thats not a suborg - thats the portfolio itself! - # In this case, we can use this as an opportunity to update address information. - self._update_portfolio_location_details( - portfolio, valid_agencies.filter(organization_name=name).first() + # You can use this to populate location information, when this occurs. + # However, this isn't needed for now so we can skip it. + message = ( + f"Skipping suborganization create on record '{name}'. " + f"The federal agency name is the same as the portfolio name." ) + TerminalHelper.colorful_logger(logger.warning, TerminalColors.YELLOW, message) else: new_suborgs.append(Suborganization(name=name, portfolio=portfolio)) @@ -165,42 +168,17 @@ class Command(BaseCommand): message = f"Updated {len(orgs_to_update)} suborganizations" TerminalHelper.colorful_logger(logger.info, TerminalColors.MAGENTA, message) - def _update_portfolio_location_details(self, portfolio: Portfolio, domain_info: DomainInformation): - """ - Update portfolio location details based on DomainInformation. - Copies relevant fields and saves the portfolio. - """ - location_props = [ - "address_line1", - "address_line2", - "city", - "state_territory", - "zipcode", - "urbanization", - ] - - for prop_name in location_props: - # Copy the value from the domain info object to the portfolio object - value = getattr(domain_info, prop_name) - setattr(portfolio, prop_name, value) - - portfolio.save() - message = f"Updated location details on portfolio '{portfolio}'" - TerminalHelper.colorful_logger(logger.info, TerminalColors.OKGREEN, message) - def handle_portfolio_requests(self, portfolio: Portfolio, federal_agency: FederalAgency): """ Associate portfolio with domain requests for a federal agency. Updates all relevant domain request records. """ invalid_states = [ - DomainRequest.DomainRequestStatus.STARTED, + DomainRequest.DomainRequestStatus.STARTED, DomainRequest.DomainRequestStatus.INELIGIBLE, DomainRequest.DomainRequestStatus.REJECTED, ] - domain_requests = DomainRequest.objects.filter( - federal_agency=federal_agency - ).exclude(status__in=invalid_states) + domain_requests = DomainRequest.objects.filter(federal_agency=federal_agency).exclude(status__in=invalid_states) if not domain_requests.exists(): message = "Portfolios not added to domain requests: no valid records found" TerminalHelper.colorful_logger(logger.info, TerminalColors.YELLOW, message) diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 78cd1aafb..5e418da2b 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -912,7 +912,6 @@ def completed_domain_request( # noqa action_needed_reason=None, portfolio=None, organization_name=None, - city=None, ): """A completed domain request.""" if not user: @@ -986,9 +985,6 @@ def completed_domain_request( # noqa if portfolio: domain_request_kwargs["portfolio"] = portfolio - if city: - domain_request_kwargs["city"] = city - domain_request, _ = DomainRequest.objects.get_or_create(**domain_request_kwargs) if has_other_contacts: diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 77822a022..5c049ac56 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -1422,13 +1422,15 @@ class TestCreateFederalPortfolio(TestCase): self.mock_client = MockSESClient() self.user = User.objects.create(username="testuser") self.federal_agency = FederalAgency.objects.create(agency="Test Federal Agency") + self.senior_official = SeniorOfficial.objects.create( + first_name="first", last_name="last", email="testuser@igorville.gov", federal_agency=self.federal_agency + ) with boto3_mocking.clients.handler_for("sesv2", self.mock_client): self.domain_request = completed_domain_request( status=DomainRequest.DomainRequestStatus.IN_REVIEW, - generic_org_type=DomainRequest.OrganizationChoices.FEDERAL, + generic_org_type=DomainRequest.OrganizationChoices.CITY, federal_agency=self.federal_agency, user=self.user, - city="WrongCity", ) self.domain_request.approve() self.domain_info = DomainInformation.objects.filter(domain_request=self.domain_request).get() @@ -1436,11 +1438,10 @@ class TestCreateFederalPortfolio(TestCase): self.domain_request_2 = completed_domain_request( name="sock@igorville.org", status=DomainRequest.DomainRequestStatus.IN_REVIEW, - generic_org_type=DomainRequest.OrganizationChoices.FEDERAL, + generic_org_type=DomainRequest.OrganizationChoices.CITY, federal_agency=self.federal_agency, user=self.user, organization_name="Test Federal Agency", - city="Block", ) self.domain_request_2.approve() self.domain_info_2 = DomainInformation.objects.filter(domain_request=self.domain_request_2).get() @@ -1450,6 +1451,7 @@ class TestCreateFederalPortfolio(TestCase): DomainRequest.objects.all().delete() Suborganization.objects.all().delete() Portfolio.objects.all().delete() + SeniorOfficial.objects.all().delete() FederalAgency.objects.all().delete() User.objects.all().delete() @@ -1477,11 +1479,8 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(suborganizations.count(), 1) self.assertEqual(suborganizations.first().name, "Testorg") - # Test other address information - self.assertEqual(portfolio.address_line1, "address 1") - self.assertEqual(portfolio.city, "Block") - self.assertEqual(portfolio.state_territory, "NY") - self.assertEqual(portfolio.zipcode, "10002") + # Test the senior official + self.assertEqual(portfolio.senior_official, self.senior_official) def test_handle_portfolio_requests(self): self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True) @@ -1535,6 +1534,7 @@ class TestCreateFederalPortfolio(TestCase): existing_portfolio.refresh_from_db() self.assertEqual(existing_portfolio.organization_name, self.federal_agency.agency) self.assertEqual(existing_portfolio.organization_type, DomainRequest.OrganizationChoices.FEDERAL) + # Notes and creator should be untouched self.assertEqual(existing_portfolio.notes, "Old notes") self.assertEqual(existing_portfolio.creator, self.user)