Continued test cleanup

This commit is contained in:
Erin Song 2024-08-27 15:52:23 -07:00
parent 2713e59795
commit ff9e73def6
No known key found for this signature in database
9 changed files with 22 additions and 238 deletions

View file

@ -7,6 +7,7 @@ from api.tests.common import less_console_noise_decorator
from .common import MockSESClient, completed_domain_request # type: ignore
from django_webtest import WebTest # type: ignore
import boto3_mocking # type: ignore
from waffle.testutils import override_flag
from registrar.models import (
DomainRequest,
@ -348,41 +349,13 @@ class DomainRequestTests(TestWithUser, WebTest):
# the post request should return a redirect to the next form in
# the domain request page
self.assertEqual(purpose_result.status_code, 302)
self.assertEqual(purpose_result["Location"], "/request/your_contact/")
num_pages_tested += 1
# ---- YOUR CONTACT INFO PAGE ----
# Follow the redirect to the next form page
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_page = purpose_result.follow()
your_contact_form = your_contact_page.forms[0]
your_contact_form["your_contact-first_name"] = "Testy you"
your_contact_form["your_contact-last_name"] = "Tester you"
your_contact_form["your_contact-title"] = "Admin Tester"
your_contact_form["your_contact-email"] = "testy-admin@town.com"
your_contact_form["your_contact-phone"] = "(201) 555 5556"
# test next button
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_result = your_contact_form.submit()
# validate that data from this step are being saved
domain_request = DomainRequest.objects.get() # there's only one
self.assertEqual(domain_request.creator.first_name, self.user.first_name)
self.assertEqual(domain_request.creator.last_name, self.user.last_name)
self.assertEqual(domain_request.creator.title, self.user.title)
self.assertEqual(domain_request.creator.email, self.user.email)
self.assertEqual(domain_request.creator.phone, self.user.phone)
# the post request should return a redirect to the next form in
# the domain request page
self.assertEqual(your_contact_result.status_code, 302)
self.assertEqual(your_contact_result["Location"], "/request/other_contacts/")
self.assertEqual(purpose_result["Location"], "/request/other_contacts/")
num_pages_tested += 1
# ---- OTHER CONTACTS PAGE ----
# Follow the redirect to the next form page
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
other_contacts_page = your_contact_result.follow()
other_contacts_page = purpose_result.follow()
# This page has 3 forms in 1.
# Let's set the yes/no radios to enable the other contacts fieldsets
@ -492,11 +465,6 @@ class DomainRequestTests(TestWithUser, WebTest):
self.assertContains(review_page, "city.gov")
self.assertContains(review_page, "city1.gov")
self.assertContains(review_page, "For all kinds of things.")
self.assertContains(review_page, "Testy you")
self.assertContains(review_page, "Tester you")
self.assertContains(review_page, "Admin Tester")
self.assertContains(review_page, "testy-admin@town.com")
self.assertContains(review_page, "(201) 555-5556")
self.assertContains(review_page, "Testy2")
self.assertContains(review_page, "Tester2")
self.assertContains(review_page, "Another Tester")
@ -704,41 +672,13 @@ class DomainRequestTests(TestWithUser, WebTest):
# the post request should return a redirect to the next form in
# the domain request page
self.assertEqual(purpose_result.status_code, 302)
self.assertEqual(purpose_result["Location"], "/request/your_contact/")
num_pages_tested += 1
# ---- YOUR CONTACT INFO PAGE ----
# Follow the redirect to the next form page
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_page = purpose_result.follow()
your_contact_form = your_contact_page.forms[0]
your_contact_form["your_contact-first_name"] = "Testy you"
your_contact_form["your_contact-last_name"] = "Tester you"
your_contact_form["your_contact-title"] = "Admin Tester"
your_contact_form["your_contact-email"] = "testy-admin@town.com"
your_contact_form["your_contact-phone"] = "(201) 555 5556"
# test next button
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_result = your_contact_form.submit()
# validate that data from this step are being saved
domain_request = DomainRequest.objects.get() # there's only one
self.assertEqual(domain_request.submitter.first_name, "Testy you")
self.assertEqual(domain_request.submitter.last_name, "Tester you")
self.assertEqual(domain_request.submitter.title, "Admin Tester")
self.assertEqual(domain_request.submitter.email, "testy-admin@town.com")
self.assertEqual(domain_request.submitter.phone, "(201) 555 5556")
# the post request should return a redirect to the next form in
# the domain request page
self.assertEqual(your_contact_result.status_code, 302)
self.assertEqual(your_contact_result["Location"], "/request/other_contacts/")
self.assertEqual(purpose_result["Location"], "/request/other_contacts/")
num_pages_tested += 1
# ---- OTHER CONTACTS PAGE ----
# Follow the redirect to the next form page
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
other_contacts_page = your_contact_result.follow()
other_contacts_page = purpose_result.follow()
# This page has 3 forms in 1.
# Let's set the yes/no radios to enable the other contacts fieldsets
@ -2264,6 +2204,7 @@ class DomainRequestTests(TestWithUser, WebTest):
senior_official = domain_request.senior_official
self.assertEquals("Testy2", senior_official.first_name)
@override_flag("profile_feature", active=True)
@less_console_noise_decorator
def test_edit_submitter_in_place(self):
"""When you:
@ -2274,13 +2215,6 @@ class DomainRequestTests(TestWithUser, WebTest):
# Populate the database with a domain request that
# has a submitter
# We'll do it from scratch
you, _ = Contact.objects.get_or_create(
first_name="Testy",
last_name="Tester",
title="Chief Tester",
email="testy@town.com",
phone="(201) 555 5555",
)
domain_request, _ = DomainRequest.objects.get_or_create(
generic_org_type="federal",
federal_type="executive",
@ -2297,7 +2231,7 @@ class DomainRequestTests(TestWithUser, WebTest):
# submitter_pk is the initial pk of the submitter. set it before update
# to be able to verify after update that the same contact object is in place
submitter_pk = you.id
creator_pk = self.user.id
# prime the form by visiting /edit
self.app.get(reverse("edit-domain-request", kwargs={"id": domain_request.pk}))
@ -2308,97 +2242,25 @@ class DomainRequestTests(TestWithUser, WebTest):
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_page = self.app.get(reverse("domain-request:your_contact"))
profile_page = self.app.get(f"/user-profile")
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_form = your_contact_page.forms[0]
profile_form = profile_page.forms[0]
# Minimal check to ensure the form is loaded
self.assertEqual(your_contact_form["your_contact-first_name"].value, "Testy")
self.assertEqual(profile_form["first_name"].value, self.user.first_name)
# update the first name of the contact
your_contact_form["your_contact-first_name"] = "Testy2"
profile_form["first_name"] = "Testy2"
# Submit the updated form
your_contact_form.submit()
profile_form.submit()
domain_request.refresh_from_db()
updated_submitter = domain_request.submitter
self.assertEquals(submitter_pk, updated_submitter.id)
self.assertEquals("Testy2", updated_submitter.first_name)
@less_console_noise_decorator
def test_edit_submitter_creates_new(self):
"""When you:
1. edit an existing your contact which IS joined to another model,
2. then submit,
the domain request is linked to a new Contact, and the new Contact is updated."""
# Populate the database with a domain request that
# has submitter assigned to it, the submitter is also
# an other contact initially
# We'll do it from scratch
submitter, _ = Contact.objects.get_or_create(
first_name="Testy",
last_name="Tester",
title="Chief Tester",
email="testy@town.com",
phone="(201) 555 5555",
)
domain_request, _ = DomainRequest.objects.get_or_create(
generic_org_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",
creator=self.user,
status="started",
)
domain_request.other_contacts.add(submitter)
# submitter_pk is the initial pk of the your contact. set it before update
# to be able to verify after update that the other contact is still in place
# and not updated, and that the new submitter has a new id
submitter_pk = submitter.id
# 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)
your_contact_page = self.app.get(reverse("domain-request:your_contact"))
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
your_contact_form = your_contact_page.forms[0]
# Minimal check to ensure the form is loaded
self.assertEqual(your_contact_form["your_contact-first_name"].value, "Testy")
# update the first name of the contact
your_contact_form["your_contact-first_name"] = "Testy2"
# Submit the updated form
your_contact_form.submit()
domain_request.refresh_from_db()
# assert that the other contact is not updated
other_contacts = domain_request.other_contacts.all()
other_contact = other_contacts[0]
self.assertEquals(submitter_pk, other_contact.id)
self.assertEquals("Testy", other_contact.first_name)
# assert that the submitter is updated
submitter = domain_request.submitter
self.assertEquals("Testy2", submitter.first_name)
updated_creator = domain_request.creator
self.assertEquals(creator_pk, updated_creator.id)
self.assertEquals("Testy2", updated_creator.first_name)
@less_console_noise_decorator
def test_domain_request_about_your_organiztion_interstate(self):
@ -2865,7 +2727,6 @@ class DomainRequestTestDifferentStatuses(TestWithUser, WebTest):
self.assertContains(detail_page, "city1.gov")
self.assertContains(detail_page, "Chief Tester")
self.assertContains(detail_page, "testy@town.com")
self.assertContains(detail_page, "Admin Tester")
self.assertContains(detail_page, "Status:")
@less_console_noise_decorator
@ -2882,7 +2743,6 @@ class DomainRequestTestDifferentStatuses(TestWithUser, WebTest):
self.assertContains(detail_page, "city.gov")
self.assertContains(detail_page, "Chief Tester")
self.assertContains(detail_page, "testy@town.com")
self.assertContains(detail_page, "Admin Tester")
self.assertContains(detail_page, "Status:")
@less_console_noise_decorator
@ -2896,7 +2756,6 @@ class DomainRequestTestDifferentStatuses(TestWithUser, WebTest):
self.assertContains(detail_page, "city1.gov")
self.assertContains(detail_page, "Chief Tester")
self.assertContains(detail_page, "testy@town.com")
self.assertContains(detail_page, "Admin Tester")
self.assertContains(detail_page, "Status:")
# click the "Withdraw request" button
mock_client = MockSESClient()
@ -2929,7 +2788,6 @@ class DomainRequestTestDifferentStatuses(TestWithUser, WebTest):
self.assertContains(detail_page, "city1.gov")
self.assertContains(detail_page, "Chief Tester")
self.assertContains(detail_page, "testy@town.com")
self.assertContains(detail_page, "Admin Tester")
self.assertContains(detail_page, "Status:")
# Restricted user trying to withdraw results in 403 error
with less_console_noise():
@ -3028,10 +2886,10 @@ class TestWizardUnlockingSteps(TestWithUser, WebTest):
self.assertEqual(detail_page.status_code, 200)
# 10 unlocked steps, one active step, the review step will have link_usa but not check_circle
self.assertContains(detail_page, "#check_circle", count=10)
self.assertContains(detail_page, "#check_circle", count=9)
# Type of organization
self.assertContains(detail_page, "usa-current", count=1)
self.assertContains(detail_page, "link_usa-checked", count=11)
self.assertContains(detail_page, "link_usa-checked", count=10)
else:
self.fail(f"Expected a redirect, but got a different response: {response}")
@ -3090,10 +2948,10 @@ class TestWizardUnlockingSteps(TestWithUser, WebTest):
# 5 unlocked steps (so, domain, submitter, other contacts, and current sites
# which unlocks if domain exists), one active step, the review step is locked
self.assertContains(detail_page, "#check_circle", count=5)
self.assertContains(detail_page, "#check_circle", count=4)
# Type of organization
self.assertContains(detail_page, "usa-current", count=1)
self.assertContains(detail_page, "link_usa-checked", count=5)
self.assertContains(detail_page, "link_usa-checked", count=4)
else:
self.fail(f"Expected a redirect, but got a different response: {response}")