mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-09 04:33:29 +02:00
fix unit test
This commit is contained in:
parent
47e8934cde
commit
9d4ab22dc4
2 changed files with 8 additions and 11 deletions
|
@ -244,7 +244,7 @@ class User(AbstractUser):
|
||||||
if permission:
|
if permission:
|
||||||
return permission.portfolio
|
return permission.portfolio
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_portfolios(self):
|
def get_portfolios(self):
|
||||||
return self.portfolio_permissions.all()
|
return self.portfolio_permissions.all()
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.utils import timezone
|
||||||
from django.test import TestCase, RequestFactory, Client
|
from django.test import TestCase, RequestFactory, Client
|
||||||
from django.contrib.admin.sites import AdminSite
|
from django.contrib.admin.sites import AdminSite
|
||||||
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
||||||
|
from django_webtest import WebTest # type: ignore
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from registrar.admin import (
|
from registrar.admin import (
|
||||||
|
@ -972,7 +973,7 @@ class TestListHeaderAdmin(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestMyUserAdmin(MockDbForSharedTests):
|
class TestMyUserAdmin(MockDbForSharedTests, WebTest):
|
||||||
"""Tests for the MyUserAdmin class as super or staff user
|
"""Tests for the MyUserAdmin class as super or staff user
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
@ -992,6 +993,7 @@ class TestMyUserAdmin(MockDbForSharedTests):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
self.app.set_user(self.superuser.username)
|
||||||
self.client = Client(HTTP_HOST="localhost:8080")
|
self.client = Client(HTTP_HOST="localhost:8080")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -1225,20 +1227,15 @@ class TestMyUserAdmin(MockDbForSharedTests):
|
||||||
|
|
||||||
self.assertNotContains(response, "Portfolio roles:")
|
self.assertNotContains(response, "Portfolio roles:")
|
||||||
self.assertNotContains(response, "Portfolio additional permissions:")
|
self.assertNotContains(response, "Portfolio additional permissions:")
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_user_can_see_related_portfolios(self):
|
def test_user_can_see_related_portfolios(self):
|
||||||
"""Tests if a user can see the portfolios they are associated with on the user page"""
|
"""Tests if a user can see the portfolios they are associated with on the user page"""
|
||||||
portfolio, _ = Portfolio.objects.get_or_create(organization_name="test", creator=self.user)
|
portfolio, _ = Portfolio.objects.get_or_create(organization_name="test", creator=self.superuser)
|
||||||
permission, _ = UserPortfolioPermission.objects.get_or_create(
|
permission, _ = UserPortfolioPermission.objects.get_or_create(
|
||||||
user=self.user, portfolio=portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
user=self.superuser, portfolio=portfolio, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
)
|
|
||||||
self.user.refresh_from_db()
|
|
||||||
self.client.force_login(self.user)
|
|
||||||
response = self.client.get(
|
|
||||||
"/admin/registrar/user/{}/change/".format(self.user.id),
|
|
||||||
follow=True,
|
|
||||||
)
|
)
|
||||||
|
response = self.app.get(reverse("admin:registrar_user_change", args=[self.superuser.pk]))
|
||||||
expected_href = reverse("admin:registrar_portfolio_change", args=[portfolio.pk])
|
expected_href = reverse("admin:registrar_portfolio_change", args=[portfolio.pk])
|
||||||
self.assertContains(response, expected_href)
|
self.assertContains(response, expected_href)
|
||||||
self.assertContains(response, str(portfolio))
|
self.assertContains(response, str(portfolio))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue