This commit is contained in:
zandercymatics 2024-07-25 09:44:10 -06:00
parent 92609f0486
commit c4d8c1a38d
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 32 additions and 19 deletions

View file

@ -13,6 +13,7 @@ from registrar.models.public_contact import PublicContact
from registrar.models.user import User from registrar.models.user import User
from registrar.models.user_domain_role import UserDomainRole from registrar.models.user_domain_role import UserDomainRole
from registrar.views.domain import DomainNameserversView from registrar.views.domain import DomainNameserversView
from registrar.models import SeniorOfficial, Suborganization
from .common import MockEppLib, less_console_noise # type: ignore from .common import MockEppLib, less_console_noise # type: ignore
from unittest.mock import patch from unittest.mock import patch
@ -87,6 +88,14 @@ class TestWithUser(MockEppLib):
super().tearDown() super().tearDown()
DomainRequest.objects.all().delete() DomainRequest.objects.all().delete()
DomainInformation.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() User.objects.all().delete()

View file

@ -1098,38 +1098,42 @@ class TestDomainSeniorOfficial(TestDomainOverview):
self.domain_information.save() self.domain_information.save()
page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id})) page = self.app.get(reverse("domain-senior-official", kwargs={"pk": self.domain.id}))
self.assertContains(page, "Testy") 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): def test_domain_senior_official_content_profile_feature(self):
"""A portfolios senior official appears on the page """A portfolios senior official appears on the page
when the profile_feature flag is on.""" 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 = Contact(first_name="Testy")
self.domain_information.senior_official.save() self.domain_information.senior_official.save()
self.domain_information.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 # Add a portfolio to the current domain
portfolio = Portfolio.objects.create(creator=self.user, organization_name="Ice Cream") 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.portfolio = portfolio
self.domain_information.save() self.domain_information.save()
self.domain_information.refresh_from_db() self.domain_information.refresh_from_db()
# Add a SO to the portfolio
senior_official = SeniorOfficial.objects.create(first_name="Bob", last_name="Unoriginal") senior_official = SeniorOfficial.objects.create(first_name="Bob", last_name="Unoriginal")
portfolio.senior_official = senior_official portfolio.senior_official = senior_official
portfolio.save() portfolio.save()
portfolio.refresh_from_db() 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 # The page should not contain the SO on domain information.
portfolio.delete() # However, the page should contain the SO on portfolio
suborganization.delete() 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): def test_domain_edit_senior_official_in_place(self):
"""When editing a senior official for domain information and SO is not """When editing a senior official for domain information and SO is not

View file

@ -23,9 +23,9 @@ from registrar.models import (
DomainInvitation, DomainInvitation,
User, User,
UserDomainRole, 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.enums import DefaultEmail
from registrar.utility.errors import ( from registrar.utility.errors import (
GenericError, GenericError,
@ -240,7 +240,7 @@ class DomainSeniorOfficialView(DomainFormBaseView):
senior_official = portfolio.senior_official if portfolio else None senior_official = portfolio.senior_official if portfolio else None
else: else:
senior_official = self.object.domain_info.senior_official 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() domain_info = self.get_domain_info_from_domain()
invalid_fields = [DomainRequest.OrganizationChoices.FEDERAL, DomainRequest.OrganizationChoices.TRIBAL] invalid_fields = [DomainRequest.OrganizationChoices.FEDERAL, DomainRequest.OrganizationChoices.TRIBAL]