unit test progress

This commit is contained in:
CocoByte 2023-12-20 15:01:54 -07:00
parent 93b978abd3
commit 515fa2c105
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F

View file

@ -729,6 +729,124 @@ class DomainApplicationTests(TestWithUser, WebTest):
actual_url_slug = no_contacts_page.request.path.split("/")[-2]
self.assertEqual(expected_url_slug, actual_url_slug)
def test_application_delete_other_contact(self):
"""Other contacts can be deleted after being saved to database."""
# Populate the databse with a domain application that
# has 1 "other contact" assigned to it
ao, _ = Contact.objects.get_or_create(
first_name="Testy",
last_name="Tester",
title="Chief Tester",
email="testy@town.com",
phone="(555) 555 5555",
)
domain, _ = DraftDomain.objects.get_or_create(name="fakeSite.gov")
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,
requested_domain=domain,
submitter=you,
creator=self.user,
)
application.other_contacts.add(other)
# prime the form by visiting /edit
url = reverse("edit-application", kwargs={"id": application.pk})
response = self.client.get(url)
url = reverse("application:other_contacts")
other_contacts_page = self.client.get(url, follow=True)
# ====== METHOD 2 -- prime form
# other_contacts_page = self.app.get(reverse("application:other_contacts"))
# session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# # Fill in the other contact form
# other_contacts_form = other_contacts_page.forms[0]
# other_contacts_form["other_contacts-0-first_name"] = "Testy2"
# other_contacts_form["other_contacts-0-last_name"] = "Tester2"
# other_contacts_form["other_contacts-0-title"] = "Another Tester"
# other_contacts_form["other_contacts-0-email"] = "testy2@town.com"
# other_contacts_form["other_contacts-0-phone"] = "(201) 555 5557"
# # for f in other_contacts_form.fields:
# # if not "submit" in f:
# # print(f)
# # print(other_contacts_form[f].value)
# # Submit the form
# other_contacts_result = other_contacts_form.submit()
# self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# # validate that data from this step are being saved
# application = DomainApplication.objects.get() # there's only one
# self.assertEqual(
# application.other_contacts.count(),
# 1,
# )
# # Verify user is taken to "anything else" page
# self.assertEqual(other_contacts_result.status_code, 302)
# self.assertEqual(other_contacts_result["Location"], "/register/anything_else/")
# # Go back to the previous step
# other_contacts_page = self.app.get(reverse("application:other_contacts"))
# clear the form
other_contacts_form = other_contacts_page.forms[0]
other_contacts_form["other_contacts-0-first_name"] = ""
other_contacts_form["other_contacts-0-middle_name"] = ""
other_contacts_form["other_contacts-0-last_name"] = ""
other_contacts_form["other_contacts-0-title"] = ""
other_contacts_form["other_contacts-0-email"] = ""
other_contacts_form["other_contacts-0-phone"] = ""
for f in other_contacts_form.fields:
if not "submit" in f:
print(f)
print(other_contacts_form[f].value)
# Submit the now empty form
result = other_contacts_form.submit()
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
# Verify that the contact we saved earlier has been removed from the database
application = DomainApplication.objects.get() # There are no contacts anymore
self.assertEqual(
application.other_contacts.count(),
0,
)
# Verify that on submit, user is advanced to "no contacts" page
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)
def test_application_about_your_organiztion_interstate(self):
"""Special districts have to answer an additional question."""
type_page = self.app.get(reverse("application:")).follow()