mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 17:01:56 +02:00
The rest of the Other Contacts unit tests
This commit is contained in:
parent
3802380490
commit
5c1147c355
2 changed files with 142 additions and 6 deletions
|
@ -441,6 +441,41 @@ class TestDomainApplication(TestCase):
|
|||
# Now, when you call is_active on Domain, it will return True
|
||||
with self.assertRaises(TransitionNotAllowed):
|
||||
self.approved_application.reject_with_prejudice()
|
||||
|
||||
def test_has_rationale_returns_true(self):
|
||||
"""has_rationale() returns true when an application has no_other_contacts_rationale"""
|
||||
self.started_application.no_other_contacts_rationale = "You talkin' to me?"
|
||||
self.started_application.save()
|
||||
|
||||
self.assertEquals(
|
||||
self.started_application.has_rationale(),
|
||||
True
|
||||
)
|
||||
|
||||
def test_has_rationale_returns_false(self):
|
||||
"""has_rationale() returns false when an application has no no_other_contacts_rationale"""
|
||||
self.assertEquals(
|
||||
self.started_application.has_rationale(),
|
||||
False
|
||||
)
|
||||
|
||||
def test_has_other_contacts_returns_true(self):
|
||||
"""has_other_contacts() returns true when an application has other_contacts"""
|
||||
# completed_application has other contacts by default
|
||||
self.assertEquals(
|
||||
self.started_application.has_other_contacts(),
|
||||
True
|
||||
)
|
||||
|
||||
def test_has_other_contacts_returns_false(self):
|
||||
"""has_other_contacts() returns false when an application has no other_contacts"""
|
||||
application = completed_application(
|
||||
status=DomainApplication.ApplicationStatus.STARTED, name="no-others.gov", has_other_contacts=False
|
||||
)
|
||||
self.assertEquals(
|
||||
application.has_other_contacts(),
|
||||
False
|
||||
)
|
||||
|
||||
|
||||
class TestPermissions(TestCase):
|
||||
|
|
|
@ -75,6 +75,7 @@ class TestWithUser(MockEppLib):
|
|||
# delete any applications too
|
||||
super().tearDown()
|
||||
DomainApplication.objects.all().delete()
|
||||
DomainInformation.objects.all().delete()
|
||||
self.user.delete()
|
||||
|
||||
|
||||
|
@ -716,13 +717,15 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
self.assertContains(contact_page, self.TITLES[Step.ABOUT_YOUR_ORGANIZATION])
|
||||
|
||||
def test_yes_no_form_inits_blank_for_new_application(self):
|
||||
""""""
|
||||
"""On the Other Contacts page, the yes/no form gets initialized with nothing selected for
|
||||
new applications"""
|
||||
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):
|
||||
""""""
|
||||
"""On the Other Contacts page, the yes/no form gets initialized with YES selected if the
|
||||
application has other contacts"""
|
||||
# Application has other contacts by default
|
||||
application = completed_application(user=self.user)
|
||||
# prime the form by visiting /edit
|
||||
|
@ -741,7 +744,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
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):
|
||||
""""""
|
||||
"""On the Other Contacts page, the yes/no form gets initialized with NO selected if the
|
||||
application has no other contacts"""
|
||||
# Application has other contacts by default
|
||||
application = completed_application(user=self.user, has_other_contacts=False)
|
||||
application.no_other_contacts_rationale = "Hello!"
|
||||
|
@ -762,7 +766,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
self.assertEquals(other_contacts_form["other_contacts-has_other_contacts"].value, "False")
|
||||
|
||||
def test_submitting_other_contacts_deletes_no_other_contacts_rationale(self):
|
||||
""""""
|
||||
"""When a user submits the Other Contacts form with other contacts selected, the application's
|
||||
no other contacts rationale gets deleted"""
|
||||
# Application has other contacts by default
|
||||
application = completed_application(user=self.user, has_other_contacts=False)
|
||||
application.no_other_contacts_rationale = "Hello!"
|
||||
|
@ -809,8 +814,9 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
)
|
||||
|
||||
def test_submitting_no_other_contacts_rationale_deletes_other_contacts(self):
|
||||
"""This also tests test_submitting_no_other_contacts_rationale_deletes_other_contacts_when_not_joined
|
||||
"""
|
||||
"""When a user submits the Other Contacts form with no other contacts selected, the application's
|
||||
other contacts get deleted for other contacts that exist and are not joined to other objects
|
||||
"""
|
||||
# Application has other contacts by default
|
||||
application = completed_application(user=self.user)
|
||||
# prime the form by visiting /edit
|
||||
|
@ -849,6 +855,101 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
"Hello again!",
|
||||
)
|
||||
|
||||
def test_submitting_no_other_contacts_rationale_removes_reference_other_contacts_when_joined(self):
|
||||
"""When a user submits the Other Contacts form with no other contacts selected, the application's
|
||||
other contacts references get removed for other contacts that exist and are joined to other objects"""
|
||||
# Populate the databse with a domain application that
|
||||
# has 1 "other contact" assigned to it
|
||||
# We'll do it from scratch so we can reuse the other contact
|
||||
ao, _ = Contact.objects.get_or_create(
|
||||
first_name="Testy",
|
||||
last_name="Tester",
|
||||
title="Chief Tester",
|
||||
email="testy@town.com",
|
||||
phone="(555) 555 5555",
|
||||
)
|
||||
you, _ = Contact.objects.get_or_create(
|
||||
first_name="Testy you",
|
||||
last_name="Tester you",
|
||||
title="Admin Tester",
|
||||
email="testy-admin@town.com",
|
||||
phone="(555) 555 5556",
|
||||
)
|
||||
other, _ = Contact.objects.get_or_create(
|
||||
first_name="Testy2",
|
||||
last_name="Tester2",
|
||||
title="Another Tester",
|
||||
email="testy2@town.com",
|
||||
phone="(555) 555 5557",
|
||||
)
|
||||
application, _ = DomainApplication.objects.get_or_create(
|
||||
organization_type="federal",
|
||||
federal_type="executive",
|
||||
purpose="Purpose of the site",
|
||||
anything_else="No",
|
||||
is_policy_acknowledged=True,
|
||||
organization_name="Testorg",
|
||||
address_line1="address 1",
|
||||
state_territory="NY",
|
||||
zipcode="10002",
|
||||
authorizing_official=ao,
|
||||
submitter=you,
|
||||
creator=self.user,
|
||||
status="started",
|
||||
)
|
||||
application.other_contacts.add(other)
|
||||
|
||||
# Now let's join the other contact to another object
|
||||
domain_info = DomainInformation.objects.create(creator=self.user)
|
||||
domain_info.other_contacts.set([other])
|
||||
|
||||
# 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 is no longer associated with the application
|
||||
application = DomainApplication.objects.get()
|
||||
self.assertEqual(
|
||||
application.other_contacts.count(),
|
||||
0,
|
||||
)
|
||||
|
||||
# Verify that the 'other' contact object still exists
|
||||
domain_info = DomainInformation.objects.get()
|
||||
self.assertEqual(
|
||||
domain_info.other_contacts.count(),
|
||||
1,
|
||||
)
|
||||
self.assertEqual(
|
||||
domain_info.other_contacts.all()[0].first_name,
|
||||
"Testy2",
|
||||
)
|
||||
|
||||
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"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue