mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
Add additional unit tests
This commit is contained in:
parent
eee745b0ca
commit
8ae6e3e30e
1 changed files with 105 additions and 18 deletions
|
@ -769,8 +769,8 @@ class DomainRequestTests(TestWithUser, WebTest):
|
||||||
anything_else"""
|
anything_else"""
|
||||||
|
|
||||||
domain_request = completed_domain_request(user=self.user, has_anything_else=True)
|
domain_request = completed_domain_request(user=self.user, has_anything_else=True)
|
||||||
domain_request.cisa_representative_email="test@igorville.gov"
|
domain_request.cisa_representative_email = "test@igorville.gov"
|
||||||
domain_request.anything_else="1234"
|
domain_request.anything_else = "1234"
|
||||||
domain_request.save()
|
domain_request.save()
|
||||||
|
|
||||||
# prime the form by visiting /edit
|
# prime the form by visiting /edit
|
||||||
|
@ -912,8 +912,10 @@ class DomainRequestTests(TestWithUser, WebTest):
|
||||||
# Make sure we have the data we need for the test
|
# Make sure we have the data we need for the test
|
||||||
self.assertEqual(domain_request.anything_else, None)
|
self.assertEqual(domain_request.anything_else, None)
|
||||||
self.assertEqual(domain_request.cisa_representative_email, 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)
|
# These fields should not be selected at all, since we haven't initialized the form yet
|
||||||
|
self.assertEqual(domain_request.has_anything_else_text, None)
|
||||||
|
self.assertEqual(domain_request.has_cisa_representative, None)
|
||||||
|
|
||||||
# prime the form by visiting /edit
|
# prime the form by visiting /edit
|
||||||
self.app.get(reverse("edit-domain-request", kwargs={"id": domain_request.pk}))
|
self.app.get(reverse("edit-domain-request", kwargs={"id": domain_request.pk}))
|
||||||
|
@ -929,17 +931,11 @@ class DomainRequestTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
additional_details_form = additional_details_page.forms[0]
|
additional_details_form = additional_details_page.forms[0]
|
||||||
|
|
||||||
# Check the cisa representative yes/no field
|
# Set fields to true, and set data on those fields
|
||||||
yes_no_cisa = additional_details_form["additional_details-has_cisa_representative"].value
|
additional_details_form["additional_details-has_cisa_representative"] = "True"
|
||||||
self.assertEquals(yes_no_cisa, "True")
|
additional_details_form["additional_details-has_anything_else_text"] = "True"
|
||||||
|
additional_details_form["additional_details-cisa_representative_email"] = "test@faketest.gov"
|
||||||
# Check the anything else yes/no field
|
additional_details_form["additional_details-anything_else"] = "redandblue"
|
||||||
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
|
# Submit the form
|
||||||
additional_details_form.submit()
|
additional_details_form.submit()
|
||||||
|
@ -949,9 +945,100 @@ class DomainRequestTests(TestWithUser, WebTest):
|
||||||
# Verify that the anything_else and cisa_representative exist in the db
|
# Verify that the anything_else and cisa_representative exist in the db
|
||||||
domain_request = DomainRequest.objects.get(requested_domain__name="cisareps.gov")
|
domain_request = DomainRequest.objects.get(requested_domain__name="cisareps.gov")
|
||||||
|
|
||||||
self.assertEqual(domain_request.anything_else, "There is more")
|
self.assertEqual(domain_request.anything_else, "redandblue")
|
||||||
self.assertEqual(domain_request.cisa_representative_email, "fake@faketown.gov")
|
self.assertEqual(domain_request.cisa_representative_email, "test@faketest.gov")
|
||||||
|
|
||||||
|
self.assertEqual(domain_request.has_cisa_representative, True)
|
||||||
|
self.assertEqual(domain_request.has_anything_else_text, True)
|
||||||
|
|
||||||
|
def test_if_cisa_representative_yes_no_form_is_yes_then_field_is_required(self):
|
||||||
|
"""Applicants with a cisa representative must provide a value"""
|
||||||
|
domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=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]
|
||||||
|
|
||||||
|
# Set fields to true, and set data on those fields
|
||||||
|
additional_details_form["additional_details-has_cisa_representative"] = "True"
|
||||||
|
additional_details_form["additional_details-has_anything_else_text"] = "False"
|
||||||
|
|
||||||
|
# Submit the form
|
||||||
|
response = additional_details_form.submit()
|
||||||
|
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
self.assertContains(response, "Enter the email address of your CISA regional representative.")
|
||||||
|
|
||||||
|
def test_if_anything_else_yes_no_form_is_yes_then_field_is_required(self):
|
||||||
|
"""Applicants with a anything else must provide a value"""
|
||||||
|
domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=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]
|
||||||
|
|
||||||
|
# Set fields to true, and set data on those fields
|
||||||
|
additional_details_form["additional_details-has_cisa_representative"] = "False"
|
||||||
|
additional_details_form["additional_details-has_anything_else_text"] = "True"
|
||||||
|
|
||||||
|
# Submit the form
|
||||||
|
response = additional_details_form.submit()
|
||||||
|
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
expected_message = "Provide additional details you’d like us to know. If you have nothing to add, select “No.”"
|
||||||
|
self.assertContains(response, expected_message)
|
||||||
|
|
||||||
|
def test_additional_details_form_fields_required(self):
|
||||||
|
"""When a user submits the Additional Details form without checking the
|
||||||
|
has_cisa_representative and has_anything_else_text fields, the form should deny this action"""
|
||||||
|
domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False)
|
||||||
|
|
||||||
|
self.assertEqual(domain_request.has_anything_else_text, None)
|
||||||
|
self.assertEqual(domain_request.has_additional_details, None)
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
|
||||||
|
# Submit the form
|
||||||
|
response = additional_details_form.submit()
|
||||||
|
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
# We expect to see this twice for both fields
|
||||||
|
self.assertContains(response, "This question is required.", count=2)
|
||||||
|
|
||||||
def test_submitting_other_contacts_deletes_no_other_contacts_rationale(self):
|
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
|
"""When a user submits the Other Contacts form with other contacts selected, the domain request's
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue