mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 17:53:31 +02:00
Testing views
This commit is contained in:
parent
d854f8327f
commit
a76d4c9da1
3 changed files with 175 additions and 22 deletions
|
@ -757,6 +757,11 @@ class NoOtherContactsForm(RegistrarForm):
|
||||||
message="Response must be less than 1000 characters.",
|
message="Response must be less than 1000 characters.",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
error_messages={
|
||||||
|
"required": (
|
||||||
|
"Rationale for no other employees is required."
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
@ -40,10 +40,6 @@
|
||||||
<h2>Organization contact {{ forloop.counter }} (optional)</h2>
|
<h2>Organization contact {{ forloop.counter }} (optional)</h2>
|
||||||
</legend>
|
</legend>
|
||||||
|
|
||||||
{% if forms.1.can_delete %}
|
|
||||||
{{ form.DELETE }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% input_with_errors form.first_name %}
|
{% input_with_errors form.first_name %}
|
||||||
|
|
||||||
{% input_with_errors form.middle_name %}
|
{% input_with_errors form.middle_name %}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from unittest import skip
|
from unittest import skip
|
||||||
|
import unittest
|
||||||
from unittest.mock import MagicMock, ANY, patch
|
from unittest.mock import MagicMock, ANY, patch
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -170,8 +171,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
in the modal header on the submit page.
|
in the modal header on the submit page.
|
||||||
"""
|
"""
|
||||||
num_pages_tested = 0
|
num_pages_tested = 0
|
||||||
# elections, type_of_work, tribal_government, no_other_contacts
|
# elections, type_of_work, tribal_government
|
||||||
SKIPPED_PAGES = 4
|
SKIPPED_PAGES = 3
|
||||||
num_pages = len(self.TITLES) - SKIPPED_PAGES
|
num_pages = len(self.TITLES) - SKIPPED_PAGES
|
||||||
|
|
||||||
type_page = self.app.get(reverse("application:")).follow()
|
type_page = self.app.get(reverse("application:")).follow()
|
||||||
|
@ -367,8 +368,13 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
# Follow the redirect to the next form page
|
# Follow the redirect to the next form page
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
other_contacts_page = your_contact_result.follow()
|
other_contacts_page = your_contact_result.follow()
|
||||||
|
|
||||||
|
# This page has 3 forms in 1.
|
||||||
|
# Let's set the yes/no radios to enable the other contacts fieldsets
|
||||||
other_contacts_form = other_contacts_page.forms[0]
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
|
||||||
|
other_contacts_form["other_contacts-has_other_contacts"] = "True"
|
||||||
|
|
||||||
other_contacts_form["other_contacts-0-first_name"] = "Testy2"
|
other_contacts_form["other_contacts-0-first_name"] = "Testy2"
|
||||||
other_contacts_form["other_contacts-0-last_name"] = "Tester2"
|
other_contacts_form["other_contacts-0-last_name"] = "Tester2"
|
||||||
other_contacts_form["other_contacts-0-title"] = "Another Tester"
|
other_contacts_form["other_contacts-0-title"] = "Another Tester"
|
||||||
|
@ -506,8 +512,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
@skip("WIP")
|
@skip("WIP")
|
||||||
def test_application_form_started_allsteps(self):
|
def test_application_form_started_allsteps(self):
|
||||||
num_pages_tested = 0
|
num_pages_tested = 0
|
||||||
# elections, type_of_work, tribal_government, no_other_contacts
|
# elections, type_of_work, tribal_government
|
||||||
SKIPPED_PAGES = 4
|
SKIPPED_PAGES = 3
|
||||||
DASHBOARD_PAGE = 1
|
DASHBOARD_PAGE = 1
|
||||||
num_pages = len(self.TITLES) - SKIPPED_PAGES + DASHBOARD_PAGE
|
num_pages = len(self.TITLES) - SKIPPED_PAGES + DASHBOARD_PAGE
|
||||||
|
|
||||||
|
@ -709,24 +715,170 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
||||||
|
|
||||||
self.assertContains(contact_page, self.TITLES[Step.ABOUT_YOUR_ORGANIZATION])
|
self.assertContains(contact_page, self.TITLES[Step.ABOUT_YOUR_ORGANIZATION])
|
||||||
|
|
||||||
def test_application_no_other_contacts(self):
|
def test_yes_no_form_inits_blank_for_new_application(self):
|
||||||
"""Applicants with no other contacts have to give a reason."""
|
""""""
|
||||||
contacts_page = self.app.get(reverse("application:other_contacts"))
|
other_contacts_page = self.app.get(reverse("application: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_application_with_other_contacts(self):
|
||||||
|
""""""
|
||||||
|
# Application has other contacts by default
|
||||||
|
application = completed_application(user=self.user)
|
||||||
|
# prime the form by visiting /edit
|
||||||
|
self.app.get(reverse("edit-application", kwargs={"id": application.pk}))
|
||||||
# django-webtest does not handle cookie-based sessions well because it keeps
|
# django-webtest does not handle cookie-based sessions well because it keeps
|
||||||
# resetting the session key on each new request, thus destroying the concept
|
# 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
|
# of a "session". We are going to do it manually, saving the session ID here
|
||||||
# and then setting the cookie on each request.
|
# and then setting the cookie on each request.
|
||||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
other_contacts_page = self.app.get(reverse("application:other_contacts"))
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "True")
|
||||||
|
|
||||||
|
def test_yes_no_form_inits_no_for_application_with_no_other_contacts_rationale(self):
|
||||||
|
""""""
|
||||||
|
# Application has other contacts by default
|
||||||
|
application = completed_application(user=self.user, has_other_contacts=False)
|
||||||
|
application.no_other_contacts_rationale = "Hello!"
|
||||||
|
application.save()
|
||||||
|
# prime the form by visiting /edit
|
||||||
|
self.app.get(reverse("edit-application", kwargs={"id": application.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)
|
||||||
|
|
||||||
|
other_contacts_page = self.app.get(reverse("application:other_contacts"))
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "False")
|
||||||
|
|
||||||
|
def test_submitting_other_contacts_deletes_no_other_contacts_rationale(self):
|
||||||
|
""""""
|
||||||
|
# Application has other contacts by default
|
||||||
|
application = completed_application(user=self.user, has_other_contacts=False)
|
||||||
|
application.no_other_contacts_rationale = "Hello!"
|
||||||
|
application.save()
|
||||||
|
# prime the form by visiting /edit
|
||||||
|
self.app.get(reverse("edit-application", kwargs={"id": application.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)
|
||||||
|
|
||||||
|
other_contacts_page = self.app.get(reverse("application:other_contacts"))
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "False")
|
||||||
|
|
||||||
|
other_contacts_form["other_contacts-has_other_contacts"] = "True"
|
||||||
|
|
||||||
|
other_contacts_form["other_contacts-0-first_name"] = "Testy"
|
||||||
|
other_contacts_form["other_contacts-0-middle_name"] = ""
|
||||||
|
other_contacts_form["other_contacts-0-last_name"] = "McTesterson"
|
||||||
|
other_contacts_form["other_contacts-0-title"] = "Lord"
|
||||||
|
other_contacts_form["other_contacts-0-email"] = "testy@abc.org"
|
||||||
|
other_contacts_form["other_contacts-0-phone"] = "(201) 555-0123"
|
||||||
|
|
||||||
|
# Submit the now empty form
|
||||||
|
other_contacts_form.submit()
|
||||||
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
result = contacts_page.forms[0].submit()
|
|
||||||
# follow first redirect
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
|
||||||
no_contacts_page = result.follow()
|
|
||||||
expected_url_slug = str(Step.NO_OTHER_CONTACTS)
|
|
||||||
actual_url_slug = no_contacts_page.request.path.split("/")[-2]
|
|
||||||
self.assertEqual(expected_url_slug, actual_url_slug)
|
|
||||||
|
|
||||||
|
# Verify that the no_other_contacts_rationale we saved earlier has been removed from the database
|
||||||
|
application = DomainApplication.objects.get()
|
||||||
|
self.assertEqual(
|
||||||
|
application.other_contacts.count(),
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEquals(
|
||||||
|
application.no_other_contacts_rationale,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_submitting_no_other_contacts_rationale_deletes_other_contacts(self):
|
||||||
|
""""""
|
||||||
|
# Application has other contacts by default
|
||||||
|
application = completed_application(user=self.user)
|
||||||
|
# prime the form by visiting /edit
|
||||||
|
self.app.get(reverse("edit-application", kwargs={"id": application.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)
|
||||||
|
|
||||||
|
other_contacts_page = self.app.get(reverse("application:other_contacts"))
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "True")
|
||||||
|
|
||||||
|
other_contacts_form["other_contacts-has_other_contacts"] = "False"
|
||||||
|
|
||||||
|
other_contacts_form["other_contacts-no_other_contacts_rationale"] = "Hello again!"
|
||||||
|
|
||||||
|
# Submit the now empty form
|
||||||
|
other_contacts_form.submit()
|
||||||
|
|
||||||
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
|
# Verify that the no_other_contacts_rationale we saved earlier has been removed from the database
|
||||||
|
application = DomainApplication.objects.get()
|
||||||
|
self.assertEqual(
|
||||||
|
application.other_contacts.count(),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEquals(
|
||||||
|
application.no_other_contacts_rationale,
|
||||||
|
"Hello again!",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_if_yes_no_form_is_no_then_no_other_contacts_required(self):
|
||||||
|
"""Applicants with no other contacts have to give a reason."""
|
||||||
|
other_contacts_page = self.app.get(reverse("application:other_contacts"))
|
||||||
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
other_contacts_form["other_contacts-has_other_contacts"] = "False"
|
||||||
|
response = other_contacts_page.forms[0].submit()
|
||||||
|
|
||||||
|
# The textarea for no other contacts returns this error message
|
||||||
|
# Assert that it is returned, ie the no other contacts form is required
|
||||||
|
self.assertContains(response, "Rationale for no other employees is required.")
|
||||||
|
|
||||||
|
# The first name field for other contacts returns this error message
|
||||||
|
# Assert that it is not returned, ie the contacts form is not required
|
||||||
|
self.assertNotContains(response, "Enter the first name / given name of this contact.")
|
||||||
|
|
||||||
|
def test_if_yes_no_form_is_yes_then_other_contacts_required(self):
|
||||||
|
"""Applicants with other contacts do not have to give a reason."""
|
||||||
|
other_contacts_page = self.app.get(reverse("application:other_contacts"))
|
||||||
|
other_contacts_form = other_contacts_page.forms[0]
|
||||||
|
other_contacts_form["other_contacts-has_other_contacts"] = "True"
|
||||||
|
response = other_contacts_page.forms[0].submit()
|
||||||
|
|
||||||
|
# The textarea for no other contacts returns this error message
|
||||||
|
# Assert that it is not returned, ie the no other contacts form is not required
|
||||||
|
self.assertNotContains(response, "Rationale for no other employees is required.")
|
||||||
|
|
||||||
|
# The first name field for other contacts returns this error message
|
||||||
|
# Assert that it is returned, ie the contacts form is required
|
||||||
|
self.assertContains(response, "Enter the first name / given name of this contact.")
|
||||||
|
|
||||||
|
@skip("Repurpose when working on ticket 903")
|
||||||
def test_application_delete_other_contact(self):
|
def test_application_delete_other_contact(self):
|
||||||
"""Other contacts can be deleted after being saved to database."""
|
"""Other contacts can be deleted after being saved to database."""
|
||||||
# Populate the databse with a domain application that
|
# Populate the databse with a domain application that
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue