diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index e5de9d49d..08fc13fa7 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -13,6 +13,7 @@ from registrar.models.public_contact import PublicContact from registrar.models.user import User from registrar.models.user_domain_role import UserDomainRole from registrar.views.domain import DomainNameserversView +from registrar.models import SeniorOfficial, Suborganization from .common import MockEppLib, less_console_noise # type: ignore from unittest.mock import patch @@ -87,6 +88,14 @@ class TestWithUser(MockEppLib): super().tearDown() DomainRequest.objects.all().delete() DomainInformation.objects.all().delete() + # For some reason, if this is done on the test directly, + # we get a django.db.models.deletion.ProtectedError on "User". + # In either event, it doesn't hurt to have these here given their + # relationship. + Suborganization.objects.all().delete() + Portfolio.objects.all().delete() + SeniorOfficial.objects.all().delete() + User.objects.all().delete() diff --git a/src/registrar/tests/test_views_domain.py b/src/registrar/tests/test_views_domain.py index 8419fa7c2..850b253e1 100644 --- a/src/registrar/tests/test_views_domain.py +++ b/src/registrar/tests/test_views_domain.py @@ -1098,38 +1098,42 @@ class TestDomainSeniorOfficial(TestDomainOverview): self.domain_information.save() page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) self.assertContains(page, "Testy") - - @override_flag("profile_feature", active=True) + + @override_flag("organization_feature", active=True) def test_domain_senior_official_content_profile_feature(self): - """A portfolios senior official appears on the page - when the profile_feature flag is on.""" + """A portfolios senior official appears on the page + when the organization_feature flag is on.""" + + # Add a SO to the domain information object self.domain_information.senior_official = Contact(first_name="Testy") self.domain_information.senior_official.save() self.domain_information.save() - # The page should not contain the SO on domain information - page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) - self.assertNotContains(page, "Testy") - # Add a portfolio to the current domain portfolio = Portfolio.objects.create(creator=self.user, organization_name="Ice Cream") - suborganization = Suborganization.objects.create(portfolio=portfolio, name="Vanilla") + Suborganization.objects.create(portfolio=portfolio, name="Vanilla") self.domain_information.portfolio = portfolio self.domain_information.save() self.domain_information.refresh_from_db() + # Add a SO to the portfolio senior_official = SeniorOfficial.objects.create(first_name="Bob", last_name="Unoriginal") portfolio.senior_official = senior_official portfolio.save() portfolio.refresh_from_db() - - # The page should contain the SO on portfolio - page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) - self.assertNotContains(page, "Bob") - # Cleanup the portfolio and suborg - portfolio.delete() - suborganization.delete() + # The page should not contain the SO on domain information. + # However, the page should contain the SO on portfolio + page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) + + # Make sure that we're on the portfolio page. + # This also implicity tests that the flag is working. + self.assertContains(page, "Suborganization") + self.assertNotContains(page, "Organization name") + + # Make sure that we're using the right SO value + self.assertNotContains(page, "Testy") + self.assertContains(page, "Bob") def test_domain_edit_senior_official_in_place(self): """When editing a senior official for domain information and SO is not diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index d41436aa7..e0b37e770 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -23,9 +23,9 @@ from registrar.models import ( DomainInvitation, User, UserDomainRole, + Portfolio, + PublicContact, ) -from registrar.models.portfolio import Portfolio -from registrar.models.public_contact import PublicContact from registrar.utility.enums import DefaultEmail from registrar.utility.errors import ( GenericError, @@ -240,7 +240,7 @@ class DomainSeniorOfficialView(DomainFormBaseView): senior_official = portfolio.senior_official if portfolio else None else: senior_official = self.object.domain_info.senior_official - form_kwargs["instance"] = senior_official + form_kwargs["instance"] = senior_official domain_info = self.get_domain_info_from_domain() invalid_fields = [DomainRequest.OrganizationChoices.FEDERAL, DomainRequest.OrganizationChoices.TRIBAL]