mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 12:39:43 +02:00
update to portfolio model and associated tests
This commit is contained in:
parent
5c061fec30
commit
d64a48934c
2 changed files with 42 additions and 0 deletions
|
@ -122,6 +122,16 @@ class Portfolio(TimeStampedModel):
|
||||||
if self.state_territory != self.StateTerritoryChoices.PUERTO_RICO and self.urbanization:
|
if self.state_territory != self.StateTerritoryChoices.PUERTO_RICO and self.urbanization:
|
||||||
self.urbanization = None
|
self.urbanization = None
|
||||||
|
|
||||||
|
# If the org type is federal, and org federal agency is not blank, and is a federal agency
|
||||||
|
# overwrite the organization name with the federal agency's agency
|
||||||
|
if (
|
||||||
|
self.organization_type == self.OrganizationChoices.FEDERAL
|
||||||
|
and self.federal_agency
|
||||||
|
and self.federal_agency != FederalAgency.get_non_federal_agency()
|
||||||
|
and self.federal_agency.agency
|
||||||
|
):
|
||||||
|
self.organization_name = self.federal_agency.agency
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -2073,13 +2073,18 @@ class TestPortfolio(TestCase):
|
||||||
self.user, _ = User.objects.get_or_create(
|
self.user, _ = User.objects.get_or_create(
|
||||||
username="intern@igorville.com", email="intern@igorville.com", first_name="Lava", last_name="World"
|
username="intern@igorville.com", email="intern@igorville.com", first_name="Lava", last_name="World"
|
||||||
)
|
)
|
||||||
|
self.non_federal_agency, _ = FederalAgency.objects.get_or_create(agency="Non-Federal Agency")
|
||||||
|
self.federal_agency, _ = FederalAgency.objects.get_or_create(agency="Federal Agency")
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
Portfolio.objects.all().delete()
|
Portfolio.objects.all().delete()
|
||||||
|
self.federal_agency.delete()
|
||||||
|
# not deleting non_federal_agency so as not to interfere potentially with other tests
|
||||||
User.objects.all().delete()
|
User.objects.all().delete()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_urbanization_field_resets_when_not_puetro_rico(self):
|
def test_urbanization_field_resets_when_not_puetro_rico(self):
|
||||||
"""The urbanization field should only be populated when the state is puetro rico.
|
"""The urbanization field should only be populated when the state is puetro rico.
|
||||||
Otherwise, this field should be empty."""
|
Otherwise, this field should be empty."""
|
||||||
|
@ -2100,6 +2105,7 @@ class TestPortfolio(TestCase):
|
||||||
self.assertEqual(portfolio.urbanization, None)
|
self.assertEqual(portfolio.urbanization, None)
|
||||||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.ALABAMA)
|
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.ALABAMA)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
def test_can_add_urbanization_field(self):
|
def test_can_add_urbanization_field(self):
|
||||||
"""Ensures that you can populate the urbanization field when conditions are right"""
|
"""Ensures that you can populate the urbanization field when conditions are right"""
|
||||||
# Create a portfolio that cannot have this field
|
# Create a portfolio that cannot have this field
|
||||||
|
@ -2121,6 +2127,32 @@ class TestPortfolio(TestCase):
|
||||||
self.assertEqual(portfolio.urbanization, "test123")
|
self.assertEqual(portfolio.urbanization, "test123")
|
||||||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.PUERTO_RICO)
|
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.PUERTO_RICO)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_organization_name_updates_for_federal_agency(self):
|
||||||
|
# Create a Portfolio instance with a federal agency
|
||||||
|
portfolio = Portfolio(
|
||||||
|
creator=self.user,
|
||||||
|
organization_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=self.federal_agency,
|
||||||
|
)
|
||||||
|
portfolio.save()
|
||||||
|
|
||||||
|
# Assert that organization_name is updated to the federal agency's name
|
||||||
|
self.assertEqual(portfolio.organization_name, "Federal Agency")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_organization_name_does_not_update_for_non_federal_agency(self):
|
||||||
|
# Create a Portfolio instance with a non-federal agency
|
||||||
|
portfolio = Portfolio(
|
||||||
|
creator=self.user,
|
||||||
|
organization_type=DomainRequest.OrganizationChoices.FEDERAL,
|
||||||
|
federal_agency=self.non_federal_agency,
|
||||||
|
)
|
||||||
|
portfolio.save()
|
||||||
|
|
||||||
|
# Assert that organization_name remains None
|
||||||
|
self.assertIsNone(portfolio.organization_name)
|
||||||
|
|
||||||
|
|
||||||
class TestAllowedEmail(TestCase):
|
class TestAllowedEmail(TestCase):
|
||||||
"""Tests our allowed email whitelist"""
|
"""Tests our allowed email whitelist"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue