mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 00:57:02 +02:00
Fix logic - WIP
This commit is contained in:
parent
1eb9b080a6
commit
eee745b0ca
4 changed files with 154 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.10 on 2024-04-18 18:21
|
||||
# Generated by Django 4.2.10 on 2024-04-22 13:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
@ -6,23 +6,19 @@ from django.db import migrations, models
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("registrar", "0084_create_groups_v11"),
|
||||
("registrar", "0086_domaininformation_updated_federal_agency_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="domaininformation",
|
||||
name="cisa_representative_email",
|
||||
field=models.EmailField(
|
||||
blank=True, db_index=True, max_length=320, null=True, verbose_name="CISA region representative"
|
||||
),
|
||||
field=models.EmailField(blank=True, max_length=320, null=True, verbose_name="CISA region representative"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="domainrequest",
|
||||
name="cisa_representative_email",
|
||||
field=models.EmailField(
|
||||
blank=True, db_index=True, max_length=320, null=True, verbose_name="CISA region representative"
|
||||
),
|
||||
field=models.EmailField(blank=True, max_length=320, null=True, verbose_name="CISA region representative"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="domainrequest",
|
|
@ -745,12 +745,22 @@ class DomainRequest(TimeStampedModel):
|
|||
"""Some yes/no forms use a db field to track whether it was checked or not.
|
||||
We handle that here for def save().
|
||||
"""
|
||||
|
||||
# This ensures that if we have prefilled data, the form is prepopulated
|
||||
if self.cisa_representative_email is not None:
|
||||
self.has_cisa_representative = self.cisa_representative_email != ""
|
||||
|
||||
# This check is required to ensure that the form doesn't start out checked
|
||||
if self.has_cisa_representative is not None:
|
||||
self.has_cisa_representative = (
|
||||
self.cisa_representative_email != "" and self.cisa_representative_email is not None
|
||||
)
|
||||
|
||||
# This ensures that if we have prefilled data, the form is prepopulated
|
||||
if self.anything_else is not None:
|
||||
self.has_anything_else_text = self.anything_else != ""
|
||||
|
||||
# This check is required to ensure that the form doesn't start out checked.
|
||||
if self.has_anything_else_text is not None:
|
||||
self.has_anything_else_text = self.anything_else != "" and self.anything_else is not None
|
||||
|
||||
|
|
|
@ -856,8 +856,6 @@ 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"
|
||||
|
|
|
@ -743,7 +743,7 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
# 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):
|
||||
def test_yes_no_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
|
||||
|
@ -763,7 +763,7 @@ 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):
|
||||
def test_yes_no_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"""
|
||||
|
@ -789,11 +789,11 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
|
||||
# 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)
|
||||
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)
|
||||
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
|
||||
|
@ -817,6 +817,142 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
other_contacts_form = other_contacts_page.forms[0]
|
||||
self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "False")
|
||||
|
||||
def test_yes_no_form_for_domain_request_with_no_cisa_representative_and_anything_else(self):
|
||||
"""On the Additional details page, the form preselects "no" when has_cisa_representative
|
||||
and anything_else is no"""
|
||||
|
||||
domain_request = completed_domain_request(user=self.user, has_anything_else=False)
|
||||
|
||||
# Unlike the other contacts form, the no button is tracked with these boolean fields.
|
||||
# This means that we should expect this to correlate with the no button.
|
||||
domain_request.has_anything_else_text = False
|
||||
domain_request.has_cisa_representative = False
|
||||
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, "False")
|
||||
|
||||
# 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, "False")
|
||||
|
||||
def test_submitting_additional_details_deletes_cisa_representative_and_anything_else(self):
|
||||
"""When a user submits the Additional Details form with no selected for all fields,
|
||||
the domain request's data gets wiped when submitted"""
|
||||
domain_request = completed_domain_request(name="nocisareps.gov", user=self.user)
|
||||
domain_request.cisa_representative_email = "fake@faketown.gov"
|
||||
domain_request.save()
|
||||
|
||||
# Make sure we have the data we need for the test
|
||||
self.assertEqual(domain_request.anything_else, "There is more")
|
||||
self.assertEqual(domain_request.cisa_representative_email, "fake@faketown.gov")
|
||||
|
||||
# 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")
|
||||
|
||||
# Set fields to false
|
||||
additional_details_form["additional_details-has_cisa_representative"] = "False"
|
||||
additional_details_form["additional_details-has_anything_else_text"] = "False"
|
||||
|
||||
# Submit the form
|
||||
additional_details_form.submit()
|
||||
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
|
||||
# Verify that the anything_else and cisa_representative have been deleted from the DB
|
||||
domain_request = DomainRequest.objects.get(requested_domain__name="nocisareps.gov")
|
||||
|
||||
# Check that our data has been cleared
|
||||
self.assertEqual(domain_request.anything_else, None)
|
||||
self.assertEqual(domain_request.cisa_representative_email, None)
|
||||
|
||||
# Double check the yes/no fields
|
||||
self.assertEqual(domain_request.has_anything_else_text, False)
|
||||
self.assertEqual(domain_request.has_cisa_representative, False)
|
||||
|
||||
def test_submitting_additional_details_populates_cisa_representative_and_anything_else(self):
|
||||
"""When a user submits the Additional Details form,
|
||||
the domain request's data gets submitted"""
|
||||
domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False)
|
||||
|
||||
# Make sure we have the data we need for the test
|
||||
self.assertEqual(domain_request.anything_else, None)
|
||||
self.assertEqual(domain_request.cisa_representative_email, None)
|
||||
self.assertEqual(domain_request.has_anything_else_text, False)
|
||||
self.assertEqual(domain_request.has_cisa_representative, False)
|
||||
|
||||
# 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")
|
||||
|
||||
# Set fields to false
|
||||
additional_details_form["additional_details-has_cisa_representative"] = "False"
|
||||
additional_details_form["additional_details-has_anything_else_text"] = "False"
|
||||
|
||||
# Submit the form
|
||||
additional_details_form.submit()
|
||||
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
|
||||
# Verify that the anything_else and cisa_representative exist in the db
|
||||
domain_request = DomainRequest.objects.get(requested_domain__name="cisareps.gov")
|
||||
|
||||
self.assertEqual(domain_request.anything_else, "There is more")
|
||||
self.assertEqual(domain_request.cisa_representative_email, "fake@faketown.gov")
|
||||
|
||||
|
||||
def test_submitting_other_contacts_deletes_no_other_contacts_rationale(self):
|
||||
"""When a user submits the Other Contacts form with other contacts selected, the domain request's
|
||||
no other contacts rationale gets deleted"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue