Merge branch 'main' into za/1901-allow-analysts-to-customize-action-needed-emails

This commit is contained in:
zandercymatics 2024-07-16 08:12:18 -06:00
commit 35c8a57aa3
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
53 changed files with 2346 additions and 2403 deletions

View file

@ -44,6 +44,7 @@ from registrar.models import (
UserGroup,
TransitionDomain,
)
from registrar.models.senior_official import SeniorOfficial
from registrar.models.user_domain_role import UserDomainRole
from registrar.models.verified_by_staff import VerifiedByStaff
from .common import (
@ -242,15 +243,11 @@ class TestDomainAdmin(MockEppLib, WebTest):
username="MrMeoward",
first_name="Meoward",
last_name="Jones",
email="meoward.jones@igorville.gov",
phone="(555) 123 12345",
title="Treat inspector",
)
# Due to the relation between User <==> Contact,
# the underlying contact has to be modified this way.
_creator.contact.email = "meoward.jones@igorville.gov"
_creator.contact.phone = "(555) 123 12345"
_creator.contact.title = "Treat inspector"
_creator.contact.save()
# Create a fake domain request
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=_creator)
domain_request.approve()
@ -935,6 +932,32 @@ class TestDomainRequestAdmin(MockEppLib):
)
self.mock_client = MockSESClient()
def test_domain_request_senior_official_is_alphabetically_sorted(self):
"""Tests if the senior offical dropdown is alphanetically sorted in the django admin display"""
SeniorOfficial.objects.get_or_create(first_name="mary", last_name="joe", title="some other guy")
SeniorOfficial.objects.get_or_create(first_name="alex", last_name="smoe", title="some guy")
SeniorOfficial.objects.get_or_create(first_name="Zoup", last_name="Soup", title="title")
contact, _ = Contact.objects.get_or_create(first_name="Henry", last_name="McFakerson")
domain_request = completed_domain_request(submitter=contact, name="city1.gov")
request = self.factory.post("/admin/registrar/domainrequest/{}/change/".format(domain_request.pk))
model_admin = AuditedAdmin(DomainRequest, self.site)
# Get the queryset that would be returned for the list
senior_offical_queryset = model_admin.formfield_for_foreignkey(
DomainInformation.senior_official.field, request
).queryset
# Make the list we're comparing on a bit prettier display-wise. Optional step.
current_sort_order = []
for official in senior_offical_queryset:
current_sort_order.append(f"{official.first_name} {official.last_name}")
expected_sort_order = ["alex smoe", "mary joe", "Zoup Soup"]
self.assertEqual(current_sort_order, expected_sort_order)
@less_console_noise_decorator
def test_has_model_description(self):
"""Tests if this model has a model description on the table view"""
@ -2113,15 +2136,11 @@ class TestDomainRequestAdmin(MockEppLib):
username="MrMeoward",
first_name="Meoward",
last_name="Jones",
email="meoward.jones@igorville.gov",
phone="(555) 123 12345",
title="Treat inspector",
)
# Due to the relation between User <==> Contact,
# the underlying contact has to be modified this way.
_creator.contact.email = "meoward.jones@igorville.gov"
_creator.contact.phone = "(555) 123 12345"
_creator.contact.title = "Treat inspector"
_creator.contact.save()
# Create a fake domain request
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=_creator)
@ -2138,11 +2157,11 @@ class TestDomainRequestAdmin(MockEppLib):
# == Check for the creator == #
# Check for the right title, email, and phone number in the response.
# Check for the right title and phone number in the response.
# Email will appear more than once
expected_creator_fields = [
# Field, expected value
("title", "Treat inspector"),
("email", "meoward.jones@igorville.gov"),
("phone", "(555) 123 12345"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields)
@ -2159,6 +2178,7 @@ class TestDomainRequestAdmin(MockEppLib):
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
self.assertContains(response, "meoward.jones@igorville.gov")
# == Check for the senior_official == #
self.assertContains(response, "testy@town.com", count=2)
@ -2778,6 +2798,7 @@ class TestDomainRequestAdmin(MockEppLib):
User.objects.all().delete()
Contact.objects.all().delete()
Website.objects.all().delete()
SeniorOfficial.objects.all().delete()
self.mock_client.EMAILS_SENT.clear()
@ -2959,6 +2980,38 @@ class TestDomainInformationAdmin(TestCase):
Domain.objects.all().delete()
Contact.objects.all().delete()
User.objects.all().delete()
SeniorOfficial.objects.all().delete()
def test_domain_information_senior_official_is_alphabetically_sorted(self):
"""Tests if the senior offical dropdown is alphanetically sorted in the django admin display"""
SeniorOfficial.objects.get_or_create(first_name="mary", last_name="joe", title="some other guy")
SeniorOfficial.objects.get_or_create(first_name="alex", last_name="smoe", title="some guy")
SeniorOfficial.objects.get_or_create(first_name="Zoup", last_name="Soup", title="title")
contact, _ = Contact.objects.get_or_create(first_name="Henry", last_name="McFakerson")
domain_request = completed_domain_request(
submitter=contact, name="city1244.gov", status=DomainRequest.DomainRequestStatus.IN_REVIEW
)
domain_request.approve()
domain_info = DomainInformation.objects.get(domain_request=domain_request)
request = self.factory.post("/admin/registrar/domaininformation/{}/change/".format(domain_info.pk))
model_admin = AuditedAdmin(DomainInformation, self.site)
# Get the queryset that would be returned for the list
senior_offical_queryset = model_admin.formfield_for_foreignkey(
DomainInformation.senior_official.field, request
).queryset
# Make the list we're comparing on a bit prettier display-wise. Optional step.
current_sort_order = []
for official in senior_offical_queryset:
current_sort_order.append(f"{official.first_name} {official.last_name}")
expected_sort_order = ["alex smoe", "mary joe", "Zoup Soup"]
self.assertEqual(current_sort_order, expected_sort_order)
@less_console_noise_decorator
def test_admin_can_see_cisa_region_federal(self):
@ -3155,15 +3208,11 @@ class TestDomainInformationAdmin(TestCase):
username="MrMeoward",
first_name="Meoward",
last_name="Jones",
email="meoward.jones@igorville.gov",
phone="(555) 123 12345",
title="Treat inspector",
)
# Due to the relation between User <==> Contact,
# the underlying contact has to be modified this way.
_creator.contact.email = "meoward.jones@igorville.gov"
_creator.contact.phone = "(555) 123 12345"
_creator.contact.title = "Treat inspector"
_creator.contact.save()
# Create a fake domain request
domain_request = completed_domain_request(status=DomainRequest.DomainRequestStatus.IN_REVIEW, user=_creator)
domain_request.approve()
@ -3185,16 +3234,16 @@ class TestDomainInformationAdmin(TestCase):
# == Check for the creator == #
# Check for the right title, email, and phone number in the response.
# Check for the right title and phone number in the response.
# We only need to check for the end tag
# (Otherwise this test will fail if we change classes, etc)
expected_creator_fields = [
# Field, expected value
("title", "Treat inspector"),
("email", "meoward.jones@igorville.gov"),
("phone", "(555) 123 12345"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_creator_fields)
self.assertContains(response, "meoward.jones@igorville.gov")
# Check for the field itself
self.assertContains(response, "Meoward Jones")
@ -3713,6 +3762,7 @@ class AuditedAdminTest(TestCase):
self.site = AdminSite()
self.factory = RequestFactory()
self.client = Client(HTTP_HOST="localhost:8080")
self.staffuser = create_user()
def order_by_desired_field_helper(self, obj_to_sort: AuditedAdmin, request, field_name, *obj_names):
with less_console_noise():
@ -3764,7 +3814,9 @@ class AuditedAdminTest(TestCase):
def test_alphabetically_sorted_fk_fields_domain_request(self):
with less_console_noise():
tested_fields = [
DomainRequest.senior_official.field,
# Senior offical is commented out for now - this is alphabetized
# and this test does not accurately reflect that.
# DomainRequest.senior_official.field,
DomainRequest.submitter.field,
# DomainRequest.investigator.field,
DomainRequest.creator.field,
@ -3822,7 +3874,9 @@ class AuditedAdminTest(TestCase):
def test_alphabetically_sorted_fk_fields_domain_information(self):
with less_console_noise():
tested_fields = [
DomainInformation.senior_official.field,
# Senior offical is commented out for now - this is alphabetized
# and this test does not accurately reflect that.
# DomainInformation.senior_official.field,
DomainInformation.submitter.field,
# DomainInformation.creator.field,
(DomainInformation.domain.field, ["name"]),
@ -3855,7 +3909,6 @@ class AuditedAdminTest(TestCase):
# Conforms to the same object structure as desired_order
current_sort_order_coerced_type = []
# This is necessary as .queryset and get_queryset
# return lists of different types/structures.
# We need to parse this data and coerce them into the same type.
@ -3932,7 +3985,8 @@ class AuditedAdminTest(TestCase):
if last_name is None:
return (first_name,)
if first_name.split(queryset_shorthand)[1] == field_name:
split_name = first_name.split(queryset_shorthand)
if len(split_name) == 2 and split_name[1] == field_name:
return returned_tuple
else:
return None
@ -4101,7 +4155,7 @@ class TestContactAdmin(TestCase):
readonly_fields = self.admin.get_readonly_fields(request)
expected_fields = ["user", "email"]
expected_fields = ["email"]
self.assertEqual(readonly_fields, expected_fields)
@ -4117,15 +4171,18 @@ class TestContactAdmin(TestCase):
self.assertEqual(readonly_fields, expected_fields)
def test_change_view_for_joined_contact_five_or_less(self):
"""Create a contact, join it to 4 domain requests. The 5th join will be a user.
Assert that the warning on the contact form lists 5 joins."""
"""Create a contact, join it to 4 domain requests.
Assert that the warning on the contact form lists 4 joins."""
with less_console_noise():
self.client.force_login(self.superuser)
# Create an instance of the model
contact, _ = Contact.objects.get_or_create(user=self.staffuser)
contact, _ = Contact.objects.get_or_create(
first_name="Henry",
last_name="McFakerson",
)
# join it to 4 domain requests. The 5th join will be a user.
# join it to 4 domain requests.
domain_request1 = completed_domain_request(submitter=contact, name="city1.gov")
domain_request2 = completed_domain_request(submitter=contact, name="city2.gov")
domain_request3 = completed_domain_request(submitter=contact, name="city3.gov")
@ -4148,24 +4205,26 @@ class TestContactAdmin(TestCase):
f"domainrequest/{domain_request3.pk}/change/'>city3.gov</a></li>"
"<li>Joined to DomainRequest: <a href='/admin/registrar/"
f"domainrequest/{domain_request4.pk}/change/'>city4.gov</a></li>"
"<li>Joined to User: <a href='/admin/registrar/"
f"user/{self.staffuser.pk}/change/'>staff@example.com</a></li>"
"</ul>",
)
def test_change_view_for_joined_contact_five_or_more(self):
"""Create a contact, join it to 5 domain requests. The 6th join will be a user.
"""Create a contact, join it to 6 domain requests.
Assert that the warning on the contact form lists 5 joins and a '1 more' ellispsis."""
with less_console_noise():
self.client.force_login(self.superuser)
# Create an instance of the model
# join it to 5 domain requests. The 6th join will be a user.
contact, _ = Contact.objects.get_or_create(user=self.staffuser)
# join it to 6 domain requests.
contact, _ = Contact.objects.get_or_create(
first_name="Henry",
last_name="McFakerson",
)
domain_request1 = completed_domain_request(submitter=contact, name="city1.gov")
domain_request2 = completed_domain_request(submitter=contact, name="city2.gov")
domain_request3 = completed_domain_request(submitter=contact, name="city3.gov")
domain_request4 = completed_domain_request(submitter=contact, name="city4.gov")
domain_request5 = completed_domain_request(submitter=contact, name="city5.gov")
completed_domain_request(submitter=contact, name="city6.gov")
with patch("django.contrib.messages.warning") as mock_warning:
# Use the test client to simulate the request
response = self.client.get(reverse("admin:registrar_contact_change", args=[contact.pk]))