diff --git a/src/registrar/management/commands/create_federal_portfolio.py b/src/registrar/management/commands/create_federal_portfolio.py index 219044fc5..017854b91 100644 --- a/src/registrar/management/commands/create_federal_portfolio.py +++ b/src/registrar/management/commands/create_federal_portfolio.py @@ -81,7 +81,8 @@ class Command(BaseCommand): else: proceed = TerminalHelper.prompt_for_execution( system_exit_on_terminate=False, - info_to_inspect=f"""The given portfolio '{federal_agency.agency}' already exists in our DB. + info_to_inspect=f""" + The given portfolio '{federal_agency.agency}' already exists in our DB. If you cancel, the rest of the script will still execute but this record will not update. """, prompt_title="Do you wish to modify this record?", @@ -126,7 +127,9 @@ class Command(BaseCommand): # Create new suborgs, as long as they don't exist in the db already new_suborgs = [] for name in org_names - set(existing_suborgs.values_list("name", flat=True)): - if name.lower() == portfolio.organization_name.lower(): + # Stored in variables due to linter wanting type information here + portfolio_name: str = portfolio.organization_name if portfolio.organization_name is not None else "" + if name is not None and name.lower() == portfolio_name.lower(): # You can use this to populate location information, when this occurs. # However, this isn't needed for now so we can skip it. message = ( diff --git a/src/registrar/tests/test_management_scripts.py b/src/registrar/tests/test_management_scripts.py index 5c049ac56..29db8a4c5 100644 --- a/src/registrar/tests/test_management_scripts.py +++ b/src/registrar/tests/test_management_scripts.py @@ -1466,6 +1466,7 @@ class TestCreateFederalPortfolio(TestCase): ) def test_create_or_modify_portfolio(self): + """Test portfolio creation and modification with suborg and senior official.""" self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True) portfolio = Portfolio.objects.get(federal_agency=self.federal_agency) @@ -1483,6 +1484,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(portfolio.senior_official, self.senior_official) def test_handle_portfolio_requests(self): + """Verify portfolio association with domain requests.""" self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True) self.domain_request.refresh_from_db() @@ -1490,6 +1492,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(self.domain_request.portfolio.federal_agency, self.federal_agency) def test_handle_portfolio_domains(self): + """Check portfolio association with domain information.""" self.run_create_federal_portfolio("Test Federal Agency", parse_domains=True) self.domain_info.refresh_from_db() @@ -1497,6 +1500,7 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(self.domain_info.portfolio.federal_agency, self.federal_agency) def test_handle_parse_both(self): + """Ensure correct parsing of both requests and domains.""" self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True, parse_domains=True) self.domain_request.refresh_from_db() @@ -1506,12 +1510,14 @@ class TestCreateFederalPortfolio(TestCase): self.assertEqual(self.domain_request.portfolio, self.domain_info.portfolio) def test_command_error_no_parse_options(self): + """Verify error when no parse options are provided.""" with self.assertRaisesRegex( CommandError, "You must specify at least one of --parse_requests or --parse_domains." ): self.run_create_federal_portfolio("Test Federal Agency") def test_command_error_agency_not_found(self): + """Check error handling for non-existent agency.""" expected_message = ( "Cannot find the federal agency 'Non-existent Agency' in our database. " "The value you enter for `agency_name` must be prepopulated in the FederalAgency table before proceeding." @@ -1520,6 +1526,7 @@ class TestCreateFederalPortfolio(TestCase): self.run_create_federal_portfolio("Non-existent Agency", parse_requests=True) def test_update_existing_portfolio(self): + """Test updating an existing portfolio.""" # Create an existing portfolio existing_portfolio = Portfolio.objects.create( federal_agency=self.federal_agency,