Merge branch 'main' into za/1948-remove-draft-domain-and-websites

This commit is contained in:
zandercymatics 2024-04-10 09:17:41 -06:00
commit e1d09a02a3
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
34 changed files with 1553 additions and 246 deletions

View file

@ -1,4 +1,6 @@
from datetime import date
from datetime import date, datetime
from django.utils import timezone
import re
from django.test import TestCase, RequestFactory, Client, override_settings
from django.contrib.admin.sites import AdminSite
from contextlib import ExitStack
@ -845,7 +847,7 @@ class TestDomainRequestAdmin(MockEppLib):
self.test_helper.assert_table_sorted("-1", ("-requested_domain__name",))
def test_submitter_sortable(self):
"""Tests if the DomainRequest sorts by domain correctly"""
"""Tests if the DomainRequest sorts by submitter correctly"""
with less_console_noise():
p = "adminpass"
self.client.login(username="superuser", password=p)
@ -876,7 +878,7 @@ class TestDomainRequestAdmin(MockEppLib):
)
def test_investigator_sortable(self):
"""Tests if the DomainRequest sorts by domain correctly"""
"""Tests if the DomainRequest sorts by investigator correctly"""
with less_console_noise():
p = "adminpass"
self.client.login(username="superuser", password=p)
@ -889,7 +891,7 @@ class TestDomainRequestAdmin(MockEppLib):
# Assert that our sort works correctly
self.test_helper.assert_table_sorted(
"6",
"12",
(
"investigator__first_name",
"investigator__last_name",
@ -898,13 +900,77 @@ class TestDomainRequestAdmin(MockEppLib):
# Assert that sorting in reverse works correctly
self.test_helper.assert_table_sorted(
"-6",
"-12",
(
"-investigator__first_name",
"-investigator__last_name",
),
)
@less_console_noise_decorator
def test_default_sorting_in_domain_requests_list(self):
"""
Make sure the default sortin in on the domain requests list page is reverse submission_date
then alphabetical requested_domain
"""
# Create domain requests with different names
domain_requests = [
completed_domain_request(status=DomainRequest.DomainRequestStatus.SUBMITTED, name=name)
for name in ["ccc.gov", "bbb.gov", "eee.gov", "aaa.gov", "zzz.gov", "ddd.gov"]
]
domain_requests[0].submission_date = timezone.make_aware(datetime(2024, 10, 16))
domain_requests[1].submission_date = timezone.make_aware(datetime(2001, 10, 16))
domain_requests[2].submission_date = timezone.make_aware(datetime(1980, 10, 16))
domain_requests[3].submission_date = timezone.make_aware(datetime(1998, 10, 16))
domain_requests[4].submission_date = timezone.make_aware(datetime(2013, 10, 16))
domain_requests[5].submission_date = timezone.make_aware(datetime(1980, 10, 16))
# Save the modified domain requests to update their attributes in the database
for domain_request in domain_requests:
domain_request.save()
# Refresh domain request objects from the database to reflect the changes
domain_requests = [DomainRequest.objects.get(pk=domain_request.pk) for domain_request in domain_requests]
# Login as superuser and retrieve the domain request list page
self.client.force_login(self.superuser)
response = self.client.get("/admin/registrar/domainrequest/")
# Check that the response is successful
self.assertEqual(response.status_code, 200)
# Extract the domain names from the response content using regex
domain_names_match = re.findall(r"(\w+\.gov)</a>", response.content.decode("utf-8"))
logger.info(f"domain_names_match {domain_names_match}")
# Verify that domain names are found
self.assertTrue(domain_names_match)
# Extract the domain names
domain_names = [match for match in domain_names_match]
# Verify that the domain names are displayed in the expected order
expected_order = [
"ccc.gov",
"zzz.gov",
"bbb.gov",
"aaa.gov",
"ddd.gov",
"eee.gov",
]
# Remove duplicates
# Remove duplicates from domain_names list while preserving order
unique_domain_names = []
for domain_name in domain_names:
if domain_name not in unique_domain_names:
unique_domain_names.append(domain_name)
self.assertEqual(unique_domain_names, expected_order)
def test_short_org_name_in_domain_requests_list(self):
"""
Make sure the short name is displaying in admin on the list page
@ -1569,9 +1635,6 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertEqual(response.status_code, 200)
self.assertContains(response, domain_request.requested_domain.name)
# Check that the modal has the right content
# Check for the header
# == Check for the creator == #
# Check for the right title, email, and phone number in the response.
@ -1587,37 +1650,38 @@ class TestDomainRequestAdmin(MockEppLib):
self.assertContains(response, "Meoward Jones")
# == Check for the submitter == #
self.assertContains(response, "mayor@igorville.gov", count=2)
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester"),
("email", "mayor@igorville.gov"),
("phone", "(555) 555 5556"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
# == Check for the authorizing_official == #
self.assertContains(response, "testy@town.com", count=2)
expected_ao_fields = [
# Field, expected value
("title", "Chief Tester"),
("email", "testy@town.com"),
("phone", "(555) 555 5555"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields)
# count=5 because the underlying domain has two users with this name.
# The dropdown has 3 of these.
self.assertContains(response, "Testy Tester", count=5)
self.assertContains(response, "Testy Tester", count=10)
# == Test the other_employees field == #
self.assertContains(response, "testy2@town.com", count=2)
expected_other_employees_fields = [
# Field, expected value
("title", "Another Tester"),
("email", "testy2@town.com"),
("phone", "(555) 555 5557"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
# Test for the copy link
self.assertContains(response, "usa-button__clipboard", count=4)
def test_save_model_sets_restricted_status_on_user(self):
with less_console_noise():
# make sure there is no user with this email
@ -1717,6 +1781,8 @@ class TestDomainRequestAdmin(MockEppLib):
"other_contacts",
"current_websites",
"alternative_domains",
"generic_org_type",
"is_election_board",
"id",
"created_at",
"updated_at",
@ -1725,12 +1791,13 @@ class TestDomainRequestAdmin(MockEppLib):
"creator",
"investigator",
"generic_org_type",
"is_election_board",
"organization_type",
"federally_recognized_tribe",
"state_recognized_tribe",
"tribe_name",
"federal_agency",
"federal_type",
"is_election_board",
"organization_name",
"address_line1",
"address_line2",
@ -1765,6 +1832,8 @@ class TestDomainRequestAdmin(MockEppLib):
"other_contacts",
"current_websites",
"alternative_domains",
"generic_org_type",
"is_election_board",
"creator",
"about_your_organization",
"requested_domain",
@ -1790,6 +1859,8 @@ class TestDomainRequestAdmin(MockEppLib):
"other_contacts",
"current_websites",
"alternative_domains",
"generic_org_type",
"is_election_board",
]
self.assertEqual(readonly_fields, expected_fields)
@ -2346,37 +2417,38 @@ class TestDomainInformationAdmin(TestCase):
self.assertContains(response, "Meoward Jones")
# == Check for the submitter == #
self.assertContains(response, "mayor@igorville.gov", count=2)
expected_submitter_fields = [
# Field, expected value
("title", "Admin Tester"),
("email", "mayor@igorville.gov"),
("phone", "(555) 555 5556"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_submitter_fields)
self.assertContains(response, "Testy2 Tester2")
# == Check for the authorizing_official == #
self.assertContains(response, "testy@town.com", count=2)
expected_ao_fields = [
# Field, expected value
("title", "Chief Tester"),
("email", "testy@town.com"),
("phone", "(555) 555 5555"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_ao_fields)
# count=5 because the underlying domain has two users with this name.
# The dropdown has 3 of these.
self.assertContains(response, "Testy Tester", count=5)
self.assertContains(response, "Testy Tester", count=10)
# == Test the other_employees field == #
self.assertContains(response, "testy2@town.com", count=2)
expected_other_employees_fields = [
# Field, expected value
("title", "Another Tester"),
("email", "testy2@town.com"),
("phone", "(555) 555 5557"),
]
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
# Test for the copy link
self.assertContains(response, "usa-button__clipboard", count=4)
def test_readonly_fields_for_analyst(self):
"""Ensures that analysts have their permissions setup correctly"""
with less_console_noise():
@ -2387,6 +2459,8 @@ class TestDomainInformationAdmin(TestCase):
expected_fields = [
"other_contacts",
"generic_org_type",
"is_election_board",
"creator",
"type_of_work",
"more_organization_information",