This commit is contained in:
zandercymatics 2024-08-30 09:31:55 -06:00
parent b3b415b563
commit 47b7ee45cc
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 12 additions and 2 deletions

View file

@ -81,7 +81,8 @@ class Command(BaseCommand):
else: else:
proceed = TerminalHelper.prompt_for_execution( proceed = TerminalHelper.prompt_for_execution(
system_exit_on_terminate=False, 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. 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?", 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 # Create new suborgs, as long as they don't exist in the db already
new_suborgs = [] new_suborgs = []
for name in org_names - set(existing_suborgs.values_list("name", flat=True)): 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. # You can use this to populate location information, when this occurs.
# However, this isn't needed for now so we can skip it. # However, this isn't needed for now so we can skip it.
message = ( message = (

View file

@ -1466,6 +1466,7 @@ class TestCreateFederalPortfolio(TestCase):
) )
def test_create_or_modify_portfolio(self): 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) self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True)
portfolio = Portfolio.objects.get(federal_agency=self.federal_agency) portfolio = Portfolio.objects.get(federal_agency=self.federal_agency)
@ -1483,6 +1484,7 @@ class TestCreateFederalPortfolio(TestCase):
self.assertEqual(portfolio.senior_official, self.senior_official) self.assertEqual(portfolio.senior_official, self.senior_official)
def test_handle_portfolio_requests(self): def test_handle_portfolio_requests(self):
"""Verify portfolio association with domain requests."""
self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True) self.run_create_federal_portfolio("Test Federal Agency", parse_requests=True)
self.domain_request.refresh_from_db() self.domain_request.refresh_from_db()
@ -1490,6 +1492,7 @@ class TestCreateFederalPortfolio(TestCase):
self.assertEqual(self.domain_request.portfolio.federal_agency, self.federal_agency) self.assertEqual(self.domain_request.portfolio.federal_agency, self.federal_agency)
def test_handle_portfolio_domains(self): def test_handle_portfolio_domains(self):
"""Check portfolio association with domain information."""
self.run_create_federal_portfolio("Test Federal Agency", parse_domains=True) self.run_create_federal_portfolio("Test Federal Agency", parse_domains=True)
self.domain_info.refresh_from_db() self.domain_info.refresh_from_db()
@ -1497,6 +1500,7 @@ class TestCreateFederalPortfolio(TestCase):
self.assertEqual(self.domain_info.portfolio.federal_agency, self.federal_agency) self.assertEqual(self.domain_info.portfolio.federal_agency, self.federal_agency)
def test_handle_parse_both(self): 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.run_create_federal_portfolio("Test Federal Agency", parse_requests=True, parse_domains=True)
self.domain_request.refresh_from_db() self.domain_request.refresh_from_db()
@ -1506,12 +1510,14 @@ class TestCreateFederalPortfolio(TestCase):
self.assertEqual(self.domain_request.portfolio, self.domain_info.portfolio) self.assertEqual(self.domain_request.portfolio, self.domain_info.portfolio)
def test_command_error_no_parse_options(self): def test_command_error_no_parse_options(self):
"""Verify error when no parse options are provided."""
with self.assertRaisesRegex( with self.assertRaisesRegex(
CommandError, "You must specify at least one of --parse_requests or --parse_domains." CommandError, "You must specify at least one of --parse_requests or --parse_domains."
): ):
self.run_create_federal_portfolio("Test Federal Agency") self.run_create_federal_portfolio("Test Federal Agency")
def test_command_error_agency_not_found(self): def test_command_error_agency_not_found(self):
"""Check error handling for non-existent agency."""
expected_message = ( expected_message = (
"Cannot find the federal agency 'Non-existent Agency' in our database. " "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." "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) self.run_create_federal_portfolio("Non-existent Agency", parse_requests=True)
def test_update_existing_portfolio(self): def test_update_existing_portfolio(self):
"""Test updating an existing portfolio."""
# Create an existing portfolio # Create an existing portfolio
existing_portfolio = Portfolio.objects.create( existing_portfolio = Portfolio.objects.create(
federal_agency=self.federal_agency, federal_agency=self.federal_agency,