mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
updated view tests, and linted
This commit is contained in:
parent
17fa1ae008
commit
a09a53e600
2 changed files with 38 additions and 3 deletions
|
@ -259,7 +259,7 @@ class User(AbstractUser):
|
||||||
|
|
||||||
def is_portfolio_admin(self, portfolio):
|
def is_portfolio_admin(self, portfolio):
|
||||||
return self.has_edit_suborganization_portfolio_permission(portfolio)
|
return self.has_edit_suborganization_portfolio_permission(portfolio)
|
||||||
|
|
||||||
def get_first_portfolio(self):
|
def get_first_portfolio(self):
|
||||||
permission = self.portfolio_permissions.first()
|
permission = self.portfolio_permissions.first()
|
||||||
if permission:
|
if permission:
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.urls import reverse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices
|
||||||
from .common import MockEppLib, MockSESClient, create_user # type: ignore
|
from .common import MockEppLib, MockSESClient, create_user # type: ignore
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
import boto3_mocking # type: ignore
|
import boto3_mocking # type: ignore
|
||||||
|
@ -342,7 +342,10 @@ class TestDomainDetail(TestDomainOverview):
|
||||||
DomainInformation.objects.get_or_create(creator=user, domain=domain, portfolio=portfolio)
|
DomainInformation.objects.get_or_create(creator=user, domain=domain, portfolio=portfolio)
|
||||||
|
|
||||||
UserPortfolioPermission.objects.get_or_create(
|
UserPortfolioPermission.objects.get_or_create(
|
||||||
user=user, portfolio=portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
user=user, portfolio=portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_MEMBER],
|
||||||
|
additional_permissions=[
|
||||||
|
UserPortfolioPermissionChoices.VIEW_ALL_DOMAINS,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
user.refresh_from_db()
|
user.refresh_from_db()
|
||||||
self.client.force_login(user)
|
self.client.force_login(user)
|
||||||
|
@ -357,6 +360,38 @@ class TestDomainDetail(TestDomainOverview):
|
||||||
# Check that user does not have option to Edit domain
|
# Check that user does not have option to Edit domain
|
||||||
self.assertNotContains(detail_page, "Edit")
|
self.assertNotContains(detail_page, "Edit")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@override_flag("organization_feature", active=True)
|
||||||
|
def test_domain_readonly_on_detail_page_for_org_admin_not_manager(self):
|
||||||
|
"""Test that a domain, which is part of a portfolio, but for which the user is not a domain manager,
|
||||||
|
properly displays read only"""
|
||||||
|
|
||||||
|
portfolio, _ = Portfolio.objects.get_or_create(organization_name="Test org", creator=self.user)
|
||||||
|
# need to create a different user than self.user because the user needs permission assignments
|
||||||
|
user = get_user_model().objects.create(
|
||||||
|
first_name="Test",
|
||||||
|
last_name="User",
|
||||||
|
email="bogus@example.gov",
|
||||||
|
phone="8003111234",
|
||||||
|
title="test title",
|
||||||
|
)
|
||||||
|
domain, _ = Domain.objects.get_or_create(name="bogusdomain.gov")
|
||||||
|
DomainInformation.objects.get_or_create(creator=user, domain=domain, portfolio=portfolio)
|
||||||
|
|
||||||
|
UserPortfolioPermission.objects.get_or_create(
|
||||||
|
user=user, portfolio=portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
|
)
|
||||||
|
user.refresh_from_db()
|
||||||
|
self.client.force_login(user)
|
||||||
|
detail_page = self.client.get(f"/domain/{domain.id}")
|
||||||
|
# Check that alert message displays properly
|
||||||
|
self.assertContains(
|
||||||
|
detail_page,
|
||||||
|
"To manage information for this domain, you must add yourself as a domain manager.",
|
||||||
|
)
|
||||||
|
# Check that user does not have option to Edit domain
|
||||||
|
self.assertNotContains(detail_page, "Edit")
|
||||||
|
|
||||||
|
|
||||||
class TestDomainManagers(TestDomainOverview):
|
class TestDomainManagers(TestDomainOverview):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue