mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 08:52:16 +02:00
Add unit test for view
This commit is contained in:
parent
7b8da895db
commit
c109d383c0
1 changed files with 46 additions and 1 deletions
|
@ -1580,7 +1580,7 @@ class TestDomainSuborganization(TestDomainOverview):
|
|||
@less_console_noise_decorator
|
||||
@override_flag("organization_feature", active=True)
|
||||
def test_edit_suborganization_field(self):
|
||||
|
||||
"""Ensure that org admins can edit the suborganization field"""
|
||||
# Create a portfolio and two suborgs
|
||||
portfolio = Portfolio.objects.create(creator=self.user, organization_name="Ice Cream")
|
||||
suborg = Suborganization.objects.create(portfolio=portfolio, name="Vanilla")
|
||||
|
@ -1635,6 +1635,51 @@ class TestDomainSuborganization(TestDomainOverview):
|
|||
self.domain_information.refresh_from_db()
|
||||
self.assertEqual(self.domain_information.sub_organization, suborg_2)
|
||||
|
||||
@less_console_noise_decorator
|
||||
@override_flag("organization_feature", active=True)
|
||||
def test_view_suborganization_field(self):
|
||||
"""Only org admins can edit the suborg field, ensure that others cannot"""
|
||||
|
||||
# Create a portfolio and two suborgs
|
||||
portfolio = Portfolio.objects.create(creator=self.user, organization_name="Ice Cream")
|
||||
suborg = Suborganization.objects.create(portfolio=portfolio, name="Vanilla")
|
||||
suborg_2 = Suborganization.objects.create(portfolio=portfolio, name="Chocolate")
|
||||
|
||||
# Create an unrelated portfolio
|
||||
unrelated_portfolio = Portfolio.objects.create(creator=self.user, organization_name="Fruit")
|
||||
unrelated_suborg = Suborganization.objects.create(portfolio=unrelated_portfolio, name="Apple")
|
||||
|
||||
# Add the portfolio to the domain_information object
|
||||
self.domain_information.portfolio = portfolio
|
||||
self.domain_information.sub_organization = suborg
|
||||
|
||||
# Add a organization_name to test if the old value still displays
|
||||
self.domain_information.organization_name = "Broccoli"
|
||||
self.domain_information.save()
|
||||
self.domain_information.refresh_from_db()
|
||||
|
||||
# Add portfolio perms to the user object
|
||||
self.user.portfolio = portfolio
|
||||
self.user.portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN_READ_ONLY]
|
||||
self.user.save()
|
||||
self.user.refresh_from_db()
|
||||
|
||||
self.assertEqual(self.domain_information.sub_organization, suborg)
|
||||
|
||||
# Navigate to the suborganization page
|
||||
page = self.app.get(reverse("domain-suborganization", kwargs={"pk": self.domain.id}))
|
||||
|
||||
# The page shouldn't contain these choices
|
||||
self.assertNotContains(page, "Vanilla")
|
||||
self.assertNotContains(page, "Chocolate")
|
||||
self.assertNotContains(page, unrelated_suborg.name)
|
||||
self.assertNotContains(page, "Save")
|
||||
|
||||
self.assertContains(
|
||||
page,
|
||||
"The suborganization for this domain can only be updated by a organization administrator."
|
||||
)
|
||||
|
||||
@less_console_noise_decorator
|
||||
@override_flag("organization_feature", active=True)
|
||||
def test_has_suborganization_field_on_overview_with_flag(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue