mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 09:43:33 +02:00
more updates to test and for linting
This commit is contained in:
parent
75ff4a591c
commit
ff86edbc35
4 changed files with 25 additions and 28 deletions
|
@ -1202,7 +1202,9 @@ class TestPortfolioInvitations(TestCase):
|
||||||
self.user.refresh_from_db()
|
self.user.refresh_from_db()
|
||||||
roles = UserPortfolioPermission.objects.filter(user=self.user)
|
roles = UserPortfolioPermission.objects.filter(user=self.user)
|
||||||
self.assertEqual(len(roles), 2)
|
self.assertEqual(len(roles), 2)
|
||||||
updated_invitation1, _ = PortfolioInvitation.objects.get_or_create(email=self.email, portfolio=self.portfolio)
|
updated_invitation1, _ = PortfolioInvitation.objects.get_or_create(
|
||||||
|
email=self.email, portfolio=self.portfolio
|
||||||
|
)
|
||||||
self.assertEqual(updated_invitation1.status, PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED)
|
self.assertEqual(updated_invitation1.status, PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED)
|
||||||
updated_invitation2, _ = PortfolioInvitation.objects.get_or_create(email=self.email, portfolio=portfolio2)
|
updated_invitation2, _ = PortfolioInvitation.objects.get_or_create(email=self.email, portfolio=portfolio2)
|
||||||
self.assertEqual(updated_invitation2.status, PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED)
|
self.assertEqual(updated_invitation2.status, PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED)
|
||||||
|
@ -1290,7 +1292,8 @@ class TestUserPortfolioPermission(TestCase):
|
||||||
portfolio_permission_2, _ = UserPortfolioPermission.objects.get_or_create(portfolio=portfolio, user=self.user)
|
portfolio_permission_2, _ = UserPortfolioPermission.objects.get_or_create(portfolio=portfolio, user=self.user)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
cm.exception.message, "Only one portfolio permission is allowed per user when multiple portfolios are disabled."
|
cm.exception.message,
|
||||||
|
"Only one portfolio permission is allowed per user when multiple portfolios are disabled.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 UserPortfolioPermissionChoices, UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import 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
|
||||||
|
|
|
@ -12,7 +12,7 @@ from registrar.models import (
|
||||||
)
|
)
|
||||||
from registrar.models.user_portfolio_permission import UserPortfolioPermission
|
from registrar.models.user_portfolio_permission import UserPortfolioPermission
|
||||||
from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices
|
||||||
from .common import create_test_user, get_wsgi_request_object
|
from .common import create_test_user
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
from django.contrib.sessions.middleware import SessionMiddleware
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
|
|
||||||
|
@ -396,9 +396,7 @@ class TestPortfolio(WebTest):
|
||||||
the portfolio should be set in session."""
|
the portfolio should be set in session."""
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
UserPortfolioPermission.objects.get_or_create(
|
UserPortfolioPermission.objects.get_or_create(user=self.user, portfolio=self.portfolio, roles=portfolio_roles)
|
||||||
user=self.user, portfolio=self.portfolio, roles=portfolio_roles
|
|
||||||
)
|
|
||||||
with override_flag("organization_feature", active=True):
|
with override_flag("organization_feature", active=True):
|
||||||
response = self.client.get(reverse("home"))
|
response = self.client.get(reverse("home"))
|
||||||
# Ensure that middleware processes the session
|
# Ensure that middleware processes the session
|
||||||
|
@ -408,9 +406,9 @@ class TestPortfolio(WebTest):
|
||||||
# Access the session via the request
|
# Access the session via the request
|
||||||
session = response.wsgi_request.session
|
session = response.wsgi_request.session
|
||||||
# Check if the 'portfolio' session variable exists
|
# Check if the 'portfolio' session variable exists
|
||||||
assert 'portfolio' in session, "Portfolio session variable should exist."
|
self.assertIn("portfolio", session, "Portfolio session variable should exist.")
|
||||||
# Check the value of the 'portfolio' session variable
|
# Check the value of the 'portfolio' session variable
|
||||||
assert session['portfolio'] == self.portfolio, "Portfolio session variable has the wrong value."
|
self.assertEqual(session["portfolio"], self.portfolio, "Portfolio session variable has the wrong value.")
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_portfolio_in_session_is_none_when_organization_feature_inactive(self):
|
def test_portfolio_in_session_is_none_when_organization_feature_inactive(self):
|
||||||
|
@ -420,9 +418,7 @@ class TestPortfolio(WebTest):
|
||||||
is false and user has a portfolio, so won't add a redundant test for that."""
|
is false and user has a portfolio, so won't add a redundant test for that."""
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
UserPortfolioPermission.objects.get_or_create(
|
UserPortfolioPermission.objects.get_or_create(user=self.user, portfolio=self.portfolio, roles=portfolio_roles)
|
||||||
user=self.user, portfolio=self.portfolio, roles=portfolio_roles
|
|
||||||
)
|
|
||||||
response = self.client.get(reverse("home"))
|
response = self.client.get(reverse("home"))
|
||||||
# Ensure that middleware processes the session
|
# Ensure that middleware processes the session
|
||||||
session_middleware = SessionMiddleware(lambda request: None)
|
session_middleware = SessionMiddleware(lambda request: None)
|
||||||
|
@ -431,9 +427,9 @@ class TestPortfolio(WebTest):
|
||||||
# Access the session via the request
|
# Access the session via the request
|
||||||
session = response.wsgi_request.session
|
session = response.wsgi_request.session
|
||||||
# Check if the 'portfolio' session variable exists
|
# Check if the 'portfolio' session variable exists
|
||||||
assert 'portfolio' in session, "Portfolio session variable should exist."
|
self.assertIn("portfolio", session, "Portfolio session variable should exist.")
|
||||||
# Check the value of the 'portfolio' session variable
|
# Check the value of the 'portfolio' session variable
|
||||||
self.assertIsNone(session['portfolio'])
|
self.assertIsNone(session["portfolio"])
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_portfolio_in_session_is_none_when_organization_feature_active_and_no_portfolio(self):
|
def test_portfolio_in_session_is_none_when_organization_feature_active_and_no_portfolio(self):
|
||||||
|
@ -449,9 +445,9 @@ class TestPortfolio(WebTest):
|
||||||
# Access the session via the request
|
# Access the session via the request
|
||||||
session = response.wsgi_request.session
|
session = response.wsgi_request.session
|
||||||
# Check if the 'portfolio' session variable exists
|
# Check if the 'portfolio' session variable exists
|
||||||
assert 'portfolio' in session, "Portfolio session variable should exist."
|
self.assertIn("portfolio", session, "Portfolio session variable should exist.")
|
||||||
# Check the value of the 'portfolio' session variable
|
# Check the value of the 'portfolio' session variable
|
||||||
self.assertIsNone(session['portfolio'])
|
self.assertIsNone(session["portfolio"])
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_portfolio_in_session_when_multiple_portfolios_active(self):
|
def test_portfolio_in_session_when_multiple_portfolios_active(self):
|
||||||
|
@ -459,9 +455,7 @@ class TestPortfolio(WebTest):
|
||||||
the portfolio should be set in session."""
|
the portfolio should be set in session."""
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
portfolio_roles = [UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
UserPortfolioPermission.objects.get_or_create(
|
UserPortfolioPermission.objects.get_or_create(user=self.user, portfolio=self.portfolio, roles=portfolio_roles)
|
||||||
user=self.user, portfolio=self.portfolio, roles=portfolio_roles
|
|
||||||
)
|
|
||||||
with override_flag("organization_feature", active=True), override_flag("multiple_portfolios", active=True):
|
with override_flag("organization_feature", active=True), override_flag("multiple_portfolios", active=True):
|
||||||
response = self.client.get(reverse("home"))
|
response = self.client.get(reverse("home"))
|
||||||
# Ensure that middleware processes the session
|
# Ensure that middleware processes the session
|
||||||
|
@ -471,9 +465,9 @@ class TestPortfolio(WebTest):
|
||||||
# Access the session via the request
|
# Access the session via the request
|
||||||
session = response.wsgi_request.session
|
session = response.wsgi_request.session
|
||||||
# Check if the 'portfolio' session variable exists
|
# Check if the 'portfolio' session variable exists
|
||||||
assert 'portfolio' in session, "Portfolio session variable should exist."
|
self.assertIn("portfolio", session, "Portfolio session variable should exist.")
|
||||||
# Check the value of the 'portfolio' session variable
|
# Check the value of the 'portfolio' session variable
|
||||||
assert session['portfolio'] == self.portfolio, "Portfolio session variable has the wrong value."
|
self.assertEqual(session["portfolio"], self.portfolio, "Portfolio session variable has the wrong value.")
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_portfolio_in_session_is_none_when_multiple_portfolios_active_and_no_portfolio(self):
|
def test_portfolio_in_session_is_none_when_multiple_portfolios_active_and_no_portfolio(self):
|
||||||
|
@ -489,9 +483,9 @@ class TestPortfolio(WebTest):
|
||||||
# Access the session via the request
|
# Access the session via the request
|
||||||
session = response.wsgi_request.session
|
session = response.wsgi_request.session
|
||||||
# Check if the 'portfolio' session variable exists
|
# Check if the 'portfolio' session variable exists
|
||||||
assert 'portfolio' in session, "Portfolio session variable should exist."
|
self.assertIn("portfolio", session, "Portfolio session variable should exist.")
|
||||||
# Check the value of the 'portfolio' session variable
|
# Check the value of the 'portfolio' session variable
|
||||||
self.assertIsNone(session['portfolio'])
|
self.assertIsNone(session["portfolio"])
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
@override_flag("organization_feature", active=True)
|
@override_flag("organization_feature", active=True)
|
||||||
|
|
|
@ -62,7 +62,7 @@ class PortfolioNoDomainsView(NoPortfolioDomainsPermissionView, View):
|
||||||
portfolio=portfolio,
|
portfolio=portfolio,
|
||||||
roles__overlap=[
|
roles__overlap=[
|
||||||
UserPortfolioRoleChoices.ORGANIZATION_ADMIN,
|
UserPortfolioRoleChoices.ORGANIZATION_ADMIN,
|
||||||
]
|
],
|
||||||
).values_list("user__id", flat=True)
|
).values_list("user__id", flat=True)
|
||||||
|
|
||||||
admin_users = User.objects.filter(id__in=admin_ids)
|
admin_users = User.objects.filter(id__in=admin_ids)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue