From c21c417b0e7ef0cd161492685f753838254195a1 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Fri, 5 Jan 2024 11:07:42 -0500 Subject: [PATCH 1/3] WIP - fixed homepage view --- src/registrar/templates/home.html | 3 ++- src/registrar/tests/test_views.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/registrar/templates/home.html b/src/registrar/templates/home.html index 15835920b..8fa3034a0 100644 --- a/src/registrar/templates/home.html +++ b/src/registrar/templates/home.html @@ -52,7 +52,8 @@

Domains

{{ domain.expiration_date|date }} - {% if domain.is_expired %} + {# UNKNOWN domains would not have an expiration date and thus would show 'Expired' #} + {% if domain.is_expired and domain.state != "unknown" %} Expired {% elif domain.state == "unknown" or domain.state == "dns needed"%} DNS needed diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 1419d34f2..491b478ca 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -1500,6 +1500,14 @@ def test_domain_detail_link_works(self): detail_page = home_page.click("Manage", index=0) self.assertContains(detail_page, "igorville.gov") self.assertContains(detail_page, "Status") + + def test_unknown_domain_does_not_show_as_expired(self): + home_page = self.app.get("/") + self.assertContains(home_page, "igorville.gov") + # click the "Edit" link + # detail_page = home_page.click("Manage", index=0) + # self.assertContains(detail_page, "igorville.gov") + # self.assertContains(detail_page, "Status") def test_domain_detail_blocked_for_ineligible_user(self): """We could easily duplicate this test for all domain management From 678ca6d95c6a2ecd1291d2ac30a6dd55c0a01ecf Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 11 Jan 2024 13:20:58 -0500 Subject: [PATCH 2/3] Account for not state unknown when displaying expiration date --- src/registrar/templates/domain_detail.html | 5 +- src/registrar/templates/home.html | 4 +- src/registrar/tests/test_views.py | 65 +++++++++++++++++++--- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/registrar/templates/domain_detail.html b/src/registrar/templates/domain_detail.html index 6d67925bc..09fc189e4 100644 --- a/src/registrar/templates/domain_detail.html +++ b/src/registrar/templates/domain_detail.html @@ -17,9 +17,10 @@ Status: - {% if domain.is_expired %} + {# UNKNOWN domains would not have an expiration date and thus would show 'Expired' #} + {% if domain.is_expired and domain.state != domain.State.UNKNOWN %} Expired - {% elif domain.state == domain.State.UNKNOWN or domain.state == domain.State.DNS_NEEDED%} + {% elif domain.state == domain.State.UNKNOWN or domain.state == domain.State.DNS_NEEDED %} DNS needed {% else %} {{ domain.state|title }} diff --git a/src/registrar/templates/home.html b/src/registrar/templates/home.html index 8fa3034a0..138f83e04 100644 --- a/src/registrar/templates/home.html +++ b/src/registrar/templates/home.html @@ -53,9 +53,9 @@

Domains

{{ domain.expiration_date|date }} {# UNKNOWN domains would not have an expiration date and thus would show 'Expired' #} - {% if domain.is_expired and domain.state != "unknown" %} + {% if domain.is_expired and domain.state != domain.State.UNKNOWN %} Expired - {% elif domain.state == "unknown" or domain.state == "dns needed"%} + {% elif domain.state == domain.State.UNKNOWN or domain.state == domain.State.DNS_NEEDED %} DNS needed {% else %} {{ domain.state|title }} diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 491b478ca..1e8a1a55b 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -35,6 +35,8 @@ User, ) from registrar.views.application import ApplicationWizard, Step +from datetime import date, datetime, timedelta +from django.utils import timezone from .common import less_console_noise @@ -1352,8 +1354,20 @@ def setUp(self): self.domain_with_ip, _ = Domain.objects.get_or_create(name="nameserverwithip.gov") self.domain_just_nameserver, _ = Domain.objects.get_or_create(name="justnameserver.com") self.domain_no_information, _ = Domain.objects.get_or_create(name="noinformation.gov") - self.domain_on_hold, _ = Domain.objects.get_or_create(name="on-hold.gov", state=Domain.State.ON_HOLD) - self.domain_deleted, _ = Domain.objects.get_or_create(name="deleted.gov", state=Domain.State.DELETED) + self.domain_on_hold, _ = Domain.objects.get_or_create( + name="on-hold.gov", + state=Domain.State.ON_HOLD, + expiration_date=timezone.make_aware( + datetime.combine(date.today() + timedelta(days=1), datetime.min.time()) + ), + ) + self.domain_deleted, _ = Domain.objects.get_or_create( + name="deleted.gov", + state=Domain.State.DELETED, + expiration_date=timezone.make_aware( + datetime.combine(date.today() + timedelta(days=1), datetime.min.time()) + ), + ) self.domain_dsdata, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov") self.domain_multdsdata, _ = Domain.objects.get_or_create(name="dnssec-multdsdata.gov") @@ -1500,14 +1514,49 @@ def test_domain_detail_link_works(self): detail_page = home_page.click("Manage", index=0) self.assertContains(detail_page, "igorville.gov") self.assertContains(detail_page, "Status") - - def test_unknown_domain_does_not_show_as_expired(self): + + def test_unknown_domain_does_not_show_as_expired_on_homepage(self): + """An UNKNOWN domain does not show as expired on the homepage. + It shows as 'DNS needed'""" + # At the time of this test's writing, there are 6 UNKNOWN domains inherited + # from constructors. Let's reset. + Domain.objects.all().delete() + UserDomainRole.objects.all().delete() + + self.domain, _ = Domain.objects.get_or_create(name="igorville.gov") + self.role, _ = UserDomainRole.objects.get_or_create( + user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER + ) + home_page = self.app.get("/") self.assertContains(home_page, "igorville.gov") - # click the "Edit" link - # detail_page = home_page.click("Manage", index=0) - # self.assertContains(detail_page, "igorville.gov") - # self.assertContains(detail_page, "Status") + igorville = Domain.objects.get(name="igorville.gov") + self.assertEquals(igorville.state, Domain.State.UNKNOWN) + self.assertNotContains(home_page, "Expired") + self.assertContains(home_page, "DNS needed") + + def test_unknown_domain_does_not_show_as_expired_on_detail_page(self): + """An UNKNOWN domain does not show as expired on the detail page. + It shows as 'DNS needed'""" + # At the time of this test's writing, there are 6 UNKNOWN domains inherited + # from constructors. Let's reset. + Domain.objects.all().delete() + UserDomainRole.objects.all().delete() + + self.domain, _ = Domain.objects.get_or_create(name="igorville.gov") + self.domain_information, _ = DomainInformation.objects.get_or_create(creator=self.user, domain=self.domain) + self.role, _ = UserDomainRole.objects.get_or_create( + user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER + ) + + home_page = self.app.get("/") + self.assertContains(home_page, "igorville.gov") + igorville = Domain.objects.get(name="igorville.gov") + self.assertEquals(igorville.state, Domain.State.UNKNOWN) + detail_page = home_page.click("Manage", index=0) + self.assertNotContains(detail_page, "Expired") + + self.assertContains(detail_page, "DNS needed") def test_domain_detail_blocked_for_ineligible_user(self): """We could easily duplicate this test for all domain management From 2e6fe68e6e9741a4dd14788b67f8cd9fbc26f6b4 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 11 Jan 2024 14:38:31 -0500 Subject: [PATCH 3/3] Remove redundant test --- src/registrar/tests/test_views.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 1e8a1a55b..2399bb90f 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -95,18 +95,6 @@ def test_home_lists_domain_applications(self): # clean up application.delete() - def test_home_lists_domains(self): - response = self.client.get("/") - domain, _ = Domain.objects.get_or_create(name="igorville.gov") - self.assertNotContains(response, "igorville.gov") - role, _ = UserDomainRole.objects.get_or_create(user=self.user, domain=domain, role=UserDomainRole.Roles.MANAGER) - response = self.client.get("/") - # count = 2 because it is also in screenreader content - self.assertContains(response, "igorville.gov", count=2) - self.assertContains(response, "Expired") - # clean up - role.delete() - def test_application_form_view(self): response = self.client.get("/register/", follow=True) self.assertContains( @@ -1522,12 +1510,12 @@ def test_unknown_domain_does_not_show_as_expired_on_homepage(self): # from constructors. Let's reset. Domain.objects.all().delete() UserDomainRole.objects.all().delete() - self.domain, _ = Domain.objects.get_or_create(name="igorville.gov") + home_page = self.app.get("/") + self.assertNotContains(home_page, "igorville.gov") self.role, _ = UserDomainRole.objects.get_or_create( user=self.user, domain=self.domain, role=UserDomainRole.Roles.MANAGER ) - home_page = self.app.get("/") self.assertContains(home_page, "igorville.gov") igorville = Domain.objects.get(name="igorville.gov")