From 7b19e29cf6800edb5c55187d8243dcb91bbb2c3d Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:58:42 -0600 Subject: [PATCH] Some unit tests --- src/registrar/models/domain_information.py | 1 - src/registrar/models/domain_request.py | 3 +- src/registrar/tests/common.py | 2 + src/registrar/tests/test_views_request.py | 48 +++++++++++++++++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/registrar/models/domain_information.py b/src/registrar/models/domain_information.py index c61f1e2a2..7d71915ba 100644 --- a/src/registrar/models/domain_information.py +++ b/src/registrar/models/domain_information.py @@ -219,7 +219,6 @@ class DomainInformation(TimeStampedModel): cisa_representative_email = models.EmailField( null=True, blank=True, - db_index=True, verbose_name="CISA region representative", max_length=320, ) diff --git a/src/registrar/models/domain_request.py b/src/registrar/models/domain_request.py index 32c0ec0c6..6da51d485 100644 --- a/src/registrar/models/domain_request.py +++ b/src/registrar/models/domain_request.py @@ -659,7 +659,6 @@ class DomainRequest(TimeStampedModel): cisa_representative_email = models.EmailField( null=True, blank=True, - db_index=True, verbose_name="CISA region representative", max_length=320, ) @@ -739,7 +738,7 @@ class DomainRequest(TimeStampedModel): self.cisa_representative_email != "" and self.cisa_representative_email is not None ) - if self.anything_else is not None: + if self.has_anything_else_text is not None: self.has_anything_else_text = self.anything_else != "" and self.anything_else is not None def __str__(self): diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 07dc08f8a..97e620813 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -857,6 +857,8 @@ def completed_domain_request( creator=user, status=status, investigator=investigator, + has_cisa_representative=False, + has_anything_else_text=False, ) if has_about_your_organization: domain_request_kwargs["about_your_organization"] = "e-Government" diff --git a/src/registrar/tests/test_views_request.py b/src/registrar/tests/test_views_request.py index a84d6c374..3d9dec37c 100644 --- a/src/registrar/tests/test_views_request.py +++ b/src/registrar/tests/test_views_request.py @@ -724,14 +724,26 @@ class DomainRequestTests(TestWithUser, WebTest): self.assertContains(contact_page, self.TITLES[Step.ABOUT_YOUR_ORGANIZATION]) - def test_yes_no_form_inits_blank_for_new_domain_request(self): + def test_yes_no_contact_form_inits_blank_for_new_domain_request(self): """On the Other Contacts page, the yes/no form gets initialized with nothing selected for new domain requests""" other_contacts_page = self.app.get(reverse("domain-request:other_contacts")) other_contacts_form = other_contacts_page.forms[0] self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, None) - def test_yes_no_form_inits_yes_for_domain_request_with_other_contacts(self): + def test_yes_no_additional_form_inits_blank_for_new_domain_request(self): + """On the Additional Details page, the yes/no form gets initialized with nothing selected for + new domain requests""" + additional_details_page = self.app.get(reverse("domain-request:additional_details")) + additional_form = additional_details_page.forms[0] + + # Check the cisa representative yes/no field + self.assertEquals(additional_form["additional_details-has_cisa_representative"].value, None) + + # Check the anything else yes/no field + self.assertEquals(additional_form["additional_details-has_anything_else_text"].value, None) + + def test_yes_no_contact_form_inits_yes_for_domain_request_with_other_contacts(self): """On the Other Contacts page, the yes/no form gets initialized with YES selected if the domain request has other contacts""" # Domain Request has other contacts by default @@ -751,6 +763,38 @@ class DomainRequestTests(TestWithUser, WebTest): other_contacts_form = other_contacts_page.forms[0] self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "True") + def test_yes_no_additional_form_inits_yes_for_cisa_representative_and_anything_else(self): + """On the Additional Details page, the yes/no form gets initialized with YES selected + for both yes/no radios if the domain request has a value for cisa_representative and + anything_else""" + + domain_request = completed_domain_request(user=self.user, has_anything_else=True) + domain_request.cisa_representative_email="test@igorville.gov" + domain_request.anything_else="1234" + domain_request.save() + + # prime the form by visiting /edit + self.app.get(reverse("edit-domain-request", kwargs={"id": domain_request.pk})) + # django-webtest does not handle cookie-based sessions well because it keeps + # resetting the session key on each new request, thus destroying the concept + # of a "session". We are going to do it manually, saving the session ID here + # and then setting the cookie on each request. + session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] + self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) + + additional_details_page = self.app.get(reverse("domain-request:additional_details")) + self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) + + additional_details_form = additional_details_page.forms[0] + + # Check the cisa representative yes/no field + yes_no_cisa = additional_details_form["additional_details-has_cisa_representative"].value + self.assertEquals(yes_no_cisa, True) + + # Check the anything else yes/no field + yes_no_anything_else = additional_details_form["additional_details-has_anything_else_text"].value + self.assertEquals(yes_no_anything_else, True) + def test_yes_no_form_inits_no_for_domain_request_with_no_other_contacts_rationale(self): """On the Other Contacts page, the yes/no form gets initialized with NO selected if the domain request has no other contacts"""