From 220560dcedbcf60d4954eae433c1da6152220806 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Wed, 3 Apr 2024 16:27:16 -0400 Subject: [PATCH 1/3] Change sort settings and unit test --- src/registrar/admin.py | 4 +- src/registrar/tests/test_admin.py | 74 ++++++++++++++++++++++++++++--- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index e0c98b7c2..9673f7df4 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1056,6 +1056,7 @@ class DomainRequestAdmin(ListHeaderAdmin): # Columns list_display = [ "requested_domain", + "submission_date", "status", "generic_org_type", "federal_type", @@ -1064,7 +1065,6 @@ class DomainRequestAdmin(ListHeaderAdmin): "custom_election_board", "city", "state_territory", - "submission_date", "submitter", "investigator", ] @@ -1192,7 +1192,7 @@ class DomainRequestAdmin(ListHeaderAdmin): filter_horizontal = ("current_websites", "alternative_domains", "other_contacts") # Table ordering - ordering = ["requested_domain__name"] + ordering = ["-submission_date", "requested_domain__name"] change_form_template = "django/admin/domain_request_change_form.html" diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 368f30721..8bdd45701 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -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 @@ -716,7 +718,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) @@ -747,7 +749,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) @@ -760,7 +762,7 @@ class TestDomainRequestAdmin(MockEppLib): # Assert that our sort works correctly self.test_helper.assert_table_sorted( - "6", + "12", ( "investigator__first_name", "investigator__last_name", @@ -769,13 +771,75 @@ 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)", 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", + "ccc.gov", + "zzz.gov", + "zzz.gov", + "bbb.gov", + "bbb.gov", + "aaa.gov", + "aaa.gov", + "ddd.gov", + "ddd.gov", + "eee.gov", + "eee.gov", + ] + self.assertEqual(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 From 2ac8a1c61cbfb04db29d92749d9c62f3c01dbb0e Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 4 Apr 2024 12:58:57 -0400 Subject: [PATCH 2/3] Fix unit test --- src/registrar/tests/test_admin.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/registrar/tests/test_admin.py b/src/registrar/tests/test_admin.py index 8bdd45701..928b68a62 100644 --- a/src/registrar/tests/test_admin.py +++ b/src/registrar/tests/test_admin.py @@ -826,19 +826,21 @@ class TestDomainRequestAdmin(MockEppLib): # Verify that the domain names are displayed in the expected order expected_order = [ "ccc.gov", - "ccc.gov", - "zzz.gov", "zzz.gov", "bbb.gov", - "bbb.gov", - "aaa.gov", "aaa.gov", "ddd.gov", - "ddd.gov", - "eee.gov", "eee.gov", ] - self.assertEqual(domain_names, expected_order) + + # 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): """ From bf6a70e9fb7ee808d6edb80c9eba538f6731c769 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Mon, 8 Apr 2024 15:31:42 -0400 Subject: [PATCH 3/3] comment --- src/registrar/admin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 9673f7df4..18bc33db6 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -1192,6 +1192,8 @@ class DomainRequestAdmin(ListHeaderAdmin): filter_horizontal = ("current_websites", "alternative_domains", "other_contacts") # Table ordering + # NOTE: This impacts the select2 dropdowns (combobox) + # Currentl, there's only one for requests on DomainInfo ordering = ["-submission_date", "requested_domain__name"] change_form_template = "django/admin/domain_request_change_form.html"