added tests and comments

This commit is contained in:
David Kennedy 2024-08-22 21:45:00 -04:00
parent 5da8119f86
commit 851e176f83
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 61 additions and 2 deletions

View file

@ -367,7 +367,9 @@ class DomainRequestAdminForm(forms.ModelForm):
class MultiFieldSortableChangeList(admin.views.main.ChangeList):
"""
This class overrides the behavior of column sorting in django admin tables in order
to allow for multi field sorting on admin_order_field
to allow for multi field sorting on admin_order_field. It also overrides behavior
of getting the filter params to allow portfolio filters to be executed without
displaying on the right side of the ChangeList view.
Usage:
@ -431,7 +433,11 @@ class MultiFieldSortableChangeList(admin.views.main.ChangeList):
def get_filters_params(self, params=None):
"""
Return all params except IGNORED_PARAMS.
Overrides the default behavior which gets filter_params, except
those in IGNORED_PARAMS. The override is to also include
portfolio in the overrides. This allows the portfolio filter
not to throw an error as a valid filter while not listing the
portfolio filter on the right side of the Change List view.
"""
params = params or self.params
lookup_params = params.copy() # a dictionary of the query string

View file

@ -14,6 +14,7 @@ from registrar.models import (
DomainInformation,
User,
Host,
Portfolio,
)
from .common import (
MockSESClient,
@ -359,6 +360,7 @@ class TestDomainAdminWithClient(TestCase):
Domain.objects.all().delete()
DomainInformation.objects.all().delete()
DomainRequest.objects.all().delete()
Portfolio.objects.all().delete()
@classmethod
def tearDownClass(self):
@ -452,6 +454,32 @@ class TestDomainAdminWithClient(TestCase):
domain_request.delete()
_creator.delete()
@less_console_noise_decorator
def test_domains_by_portfolio(self):
"""
Tests that domains display for a portfolio.
"""
portfolio, _ = Portfolio.objects.get_or_create(organization_name="Test Portfolio", creator=self.superuser)
# Create a fake domain request and domain
_domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.IN_REVIEW, portfolio=portfolio
)
_domain_request.approve()
domain = _domain_request.approved_domain
self.client.force_login(self.superuser)
response = self.client.get(
"/admin/registrar/domain/?portfolio={}".format(portfolio.pk),
follow=True,
)
# Make sure the page loaded, and that we're on the right page
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain.name)
self.assertContains(response, portfolio.organization_name)
@less_console_noise_decorator
def test_helper_text(self):
"""

View file

@ -22,6 +22,7 @@ from registrar.models import (
Contact,
Website,
SeniorOfficial,
Portfolio,
)
from .common import (
MockSESClient,
@ -78,6 +79,7 @@ class TestDomainRequestAdmin(MockEppLib):
Contact.objects.all().delete()
Website.objects.all().delete()
SeniorOfficial.objects.all().delete()
Portfolio.objects.all().delete()
self.mock_client.EMAILS_SENT.clear()
@classmethod
@ -263,6 +265,29 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertContains(response, domain_request.requested_domain.name)
self.assertContains(response, "<span>Show details</span>")
@less_console_noise_decorator
def test_domain_requests_by_portfolio(self):
"""
Tests that domain_requests display for a portfolio.
"""
portfolio, _ = Portfolio.objects.get_or_create(organization_name="Test Portfolio", creator=self.superuser)
# Create a fake domain request and domain
domain_request = completed_domain_request(
status=DomainRequest.DomainRequestStatus.IN_REVIEW, portfolio=portfolio
)
self.client.force_login(self.superuser)
response = self.client.get(
"/admin/registrar/domainrequest/?portfolio={}".format(portfolio.pk),
follow=True,
)
# Make sure the page loaded, and that we're on the right page
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain_request.requested_domain.name)
self.assertContains(response, portfolio.organization_name)
@less_console_noise_decorator
def test_analyst_can_see_and_edit_alternative_domain(self):
"""Tests if an analyst can still see and edit the alternative domain field"""