fixed unit tests (still need to rethink how to handle deletion of CISA rep contacts)

This commit is contained in:
CocoByte 2024-05-20 13:30:51 -06:00
parent d9cc947f6e
commit 7dc9dba833
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
6 changed files with 41 additions and 27 deletions

View file

@ -1376,7 +1376,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
"authorizing_official", "authorizing_official",
"other_contacts", "other_contacts",
"no_other_contacts_rationale", "no_other_contacts_rationale",
"cisa_representative_email", "cisa_representative",
] ]
}, },
), ),
@ -1452,7 +1452,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
"no_other_contacts_rationale", "no_other_contacts_rationale",
"anything_else", "anything_else",
"is_policy_acknowledged", "is_policy_acknowledged",
"cisa_representative_email", "cisa_representative",
] ]
autocomplete_fields = [ autocomplete_fields = [
"approved_domain", "approved_domain",

View file

@ -649,14 +649,10 @@ class NoOtherContactsForm(BaseDeletableRegistrarForm):
class CisaRepresentativeForm(BaseDeletableRegistrarForm): class CisaRepresentativeForm(BaseDeletableRegistrarForm):
JOIN = "cisa_representative" JOIN = "cisa_representative"
logger.debug("GETTING CISA REP")
def to_database(self, obj): def to_database(self, obj):
logger.debug("SAVING CISA REP")
if not self.is_valid(): if not self.is_valid():
return return
contact = getattr(obj, "cisa_representative", None) contact = getattr(obj, "cisa_representative", None)
logger.debug("EXISTING REP: %s" % contact)
if contact is not None and not contact.has_more_than_one_join("cisa_representative_domain_requests"): if contact is not None and not contact.has_more_than_one_join("cisa_representative_domain_requests"):
# if contact exists in the database and is not joined to other entities # if contact exists in the database and is not joined to other entities
super().to_database(contact) super().to_database(contact)
@ -665,7 +661,6 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
# in either case, create a new contact and update it # in either case, create a new contact and update it
contact = Contact() contact = Contact()
super().to_database(contact) super().to_database(contact)
logger.debug("NEW REP: %s" % contact)
obj.cisa_representative = contact obj.cisa_representative = contact
obj.save() obj.save()

View file

@ -812,6 +812,7 @@ def completed_domain_request(
has_alternative_gov_domain=True, has_alternative_gov_domain=True,
has_about_your_organization=True, has_about_your_organization=True,
has_anything_else=True, has_anything_else=True,
has_cisa_representative=True,
status=DomainRequest.DomainRequestStatus.STARTED, status=DomainRequest.DomainRequestStatus.STARTED,
user=False, user=False,
submitter=False, submitter=False,
@ -893,6 +894,13 @@ def completed_domain_request(
domain_request.current_websites.add(current) domain_request.current_websites.add(current)
if has_alternative_gov_domain: if has_alternative_gov_domain:
domain_request.alternative_domains.add(alt) domain_request.alternative_domains.add(alt)
if has_cisa_representative:
cisa_representative, _ = Contact.objects.get_or_create(
first_name="CISA-first-name",
last_name="CISA-last-name",
email="cisaRep@igorville.gov",
)
domain_request.cisa_representative = cisa_representative
return domain_request return domain_request

View file

@ -2263,7 +2263,7 @@ class TestDomainRequestAdmin(MockEppLib):
"no_other_contacts_rationale", "no_other_contacts_rationale",
"anything_else", "anything_else",
"has_anything_else_text", "has_anything_else_text",
"cisa_representative_email", "cisa_representative",
"has_cisa_representative", "has_cisa_representative",
"is_policy_acknowledged", "is_policy_acknowledged",
"submission_date", "submission_date",
@ -2296,7 +2296,7 @@ class TestDomainRequestAdmin(MockEppLib):
"no_other_contacts_rationale", "no_other_contacts_rationale",
"anything_else", "anything_else",
"is_policy_acknowledged", "is_policy_acknowledged",
"cisa_representative_email", "cisa_representative",
] ]
self.assertEqual(readonly_fields, expected_fields) self.assertEqual(readonly_fields, expected_fields)

View file

@ -369,7 +369,9 @@ class DomainRequestTests(TestWithUser, WebTest):
additional_details_form["additional_details-has_cisa_representative"] = "True" additional_details_form["additional_details-has_cisa_representative"] = "True"
additional_details_form["additional_details-has_anything_else_text"] = "True" additional_details_form["additional_details-has_anything_else_text"] = "True"
additional_details_form["additional_details-cisa_representative_email"] = "FakeEmail@gmail.com" additional_details_form["additional_details-first_name"] = "CISA-first-name"
additional_details_form["additional_details-last_name"] = "CISA-last-name"
additional_details_form["additional_details-email"] = "FakeEmail@gmail.com"
additional_details_form["additional_details-anything_else"] = "Nothing else." additional_details_form["additional_details-anything_else"] = "Nothing else."
# test next button # test next button
@ -377,7 +379,9 @@ class DomainRequestTests(TestWithUser, WebTest):
additional_details_result = additional_details_form.submit() additional_details_result = additional_details_form.submit()
# validate that data from this step are being saved # validate that data from this step are being saved
domain_request = DomainRequest.objects.get() # there's only one domain_request = DomainRequest.objects.get() # there's only one
self.assertEqual(domain_request.cisa_representative_email, "FakeEmail@gmail.com") self.assertEqual(domain_request.cisa_representative.first_name, "CISA-first-name")
self.assertEqual(domain_request.cisa_representative.last_name, "CISA-last-name")
self.assertEqual(domain_request.cisa_representative.email, "FakeEmail@gmail.com")
self.assertEqual(domain_request.anything_else, "Nothing else.") self.assertEqual(domain_request.anything_else, "Nothing else.")
# the post request should return a redirect to the next form in # the post request should return a redirect to the next form in
# the domain request page # the domain request page
@ -814,8 +818,7 @@ class DomainRequestTests(TestWithUser, WebTest):
for both yes/no radios if the domain request has a value for cisa_representative and for both yes/no radios if the domain request has a value for cisa_representative and
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, has_cisa_representative=True)
domain_request.cisa_representative_email = "test@igorville.gov"
domain_request.anything_else = "1234" domain_request.anything_else = "1234"
domain_request.save() domain_request.save()
@ -867,12 +870,11 @@ class DomainRequestTests(TestWithUser, WebTest):
"""On the Additional details page, the form preselects "no" when has_cisa_representative """On the Additional details page, the form preselects "no" when has_cisa_representative
and anything_else is no""" and anything_else is no"""
domain_request = completed_domain_request(user=self.user, has_anything_else=False) domain_request = completed_domain_request(user=self.user, has_anything_else=False, has_cisa_representative=False)
# Unlike the other contacts form, the no button is tracked with these boolean fields. # Unlike the other contacts form, the no button is tracked with these boolean fields.
# This means that we should expect this to correlate with the no button. # This means that we should expect this to correlate with the no button.
domain_request.has_anything_else_text = False domain_request.has_anything_else_text = False
domain_request.has_cisa_representative = False
domain_request.save() domain_request.save()
# prime the form by visiting /edit # prime the form by visiting /edit
@ -891,7 +893,7 @@ class DomainRequestTests(TestWithUser, WebTest):
# Check the cisa representative yes/no field # Check the cisa representative yes/no field
yes_no_cisa = additional_details_form["additional_details-has_cisa_representative"].value yes_no_cisa = additional_details_form["additional_details-has_cisa_representative"].value
self.assertEquals(yes_no_cisa, "False") self.assertEquals(yes_no_cisa, None)
# Check the anything else yes/no field # Check the anything else yes/no field
yes_no_anything_else = additional_details_form["additional_details-has_anything_else_text"].value yes_no_anything_else = additional_details_form["additional_details-has_anything_else_text"].value
@ -901,12 +903,16 @@ class DomainRequestTests(TestWithUser, WebTest):
"""When a user submits the Additional Details form with no selected for all fields, """When a user submits the Additional Details form with no selected for all fields,
the domain request's data gets wiped when submitted""" the domain request's data gets wiped when submitted"""
domain_request = completed_domain_request(name="nocisareps.gov", user=self.user) domain_request = completed_domain_request(name="nocisareps.gov", user=self.user)
domain_request.cisa_representative_email = "fake@faketown.gov" domain_request.cisa_representative.first_name = "cisa-firstname1"
domain_request.cisa_representative.last_name = "cisa-lastname1"
domain_request.cisa_representative.email = "fake@faketown.gov"
domain_request.save() domain_request.save()
# 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, "There is more") self.assertEqual(domain_request.anything_else, "There is more")
self.assertEqual(domain_request.cisa_representative_email, "fake@faketown.gov") self.assertEqual(domain_request.cisa_representative.first_name, "cisa-firstname1")
self.assertEqual(domain_request.cisa_representative.last_name, "cisa-lastname1")
self.assertEqual(domain_request.cisa_representative.email, "fake@faketown.gov")
# 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}))
@ -944,7 +950,7 @@ class DomainRequestTests(TestWithUser, WebTest):
# Check that our data has been cleared # Check that our data has been cleared
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, None)
# Double check the yes/no fields # Double check the yes/no fields
self.assertEqual(domain_request.has_anything_else_text, False) self.assertEqual(domain_request.has_anything_else_text, False)
@ -953,11 +959,11 @@ class DomainRequestTests(TestWithUser, WebTest):
def test_submitting_additional_details_populates_cisa_representative_and_anything_else(self): def test_submitting_additional_details_populates_cisa_representative_and_anything_else(self):
"""When a user submits the Additional Details form, """When a user submits the Additional Details form,
the domain request's data gets submitted""" the domain request's data gets submitted"""
domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False) domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False, has_cisa_representative=False)
# 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, None)
# These fields should not be selected at all, since we haven't initialized the form yet # 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_anything_else_text, None)
@ -980,7 +986,9 @@ class DomainRequestTests(TestWithUser, WebTest):
# Set fields to true, and set data on those fields # 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_cisa_representative"] = "True"
additional_details_form["additional_details-has_anything_else_text"] = "True" additional_details_form["additional_details-has_anything_else_text"] = "True"
additional_details_form["additional_details-cisa_representative_email"] = "test@faketest.gov" additional_details_form["additional_details-first_name"] = "cisa-firstname"
additional_details_form["additional_details-last_name"] = "cisa-lastname"
additional_details_form["additional_details-email"] = "test@faketest.gov"
additional_details_form["additional_details-anything_else"] = "redandblue" additional_details_form["additional_details-anything_else"] = "redandblue"
# Submit the form # Submit the form
@ -992,14 +1000,16 @@ class DomainRequestTests(TestWithUser, WebTest):
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, "redandblue") self.assertEqual(domain_request.anything_else, "redandblue")
self.assertEqual(domain_request.cisa_representative_email, "test@faketest.gov") self.assertEqual(domain_request.cisa_representative.first_name, "cisa-firstname")
self.assertEqual(domain_request.cisa_representative.last_name, "cisa-lastname")
self.assertEqual(domain_request.cisa_representative.email, "test@faketest.gov")
self.assertEqual(domain_request.has_cisa_representative, True) self.assertEqual(domain_request.has_cisa_representative, True)
self.assertEqual(domain_request.has_anything_else_text, 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): def test_if_cisa_representative_yes_no_form_is_yes_then_field_is_required(self):
"""Applicants with a cisa representative must provide a value""" """Applicants with a cisa representative must provide a value"""
domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False) domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False, has_cisa_representative=False)
# 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}))
@ -1024,7 +1034,8 @@ class DomainRequestTests(TestWithUser, WebTest):
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
self.assertContains(response, "Enter the email address of your CISA regional representative.") self.assertContains(response, "Enter your first name / given name.")
self.assertContains(response, "Enter your last name / family name.")
def test_if_anything_else_yes_no_form_is_yes_then_field_is_required(self): def test_if_anything_else_yes_no_form_is_yes_then_field_is_required(self):
"""Applicants with a anything else must provide a value""" """Applicants with a anything else must provide a value"""
@ -1059,7 +1070,7 @@ class DomainRequestTests(TestWithUser, WebTest):
def test_additional_details_form_fields_required(self): def test_additional_details_form_fields_required(self):
"""When a user submits the Additional Details form without checking the """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""" 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) domain_request = completed_domain_request(name="cisareps.gov", user=self.user, has_anything_else=False, has_cisa_representative=False)
self.assertEqual(domain_request.has_anything_else_text, None) self.assertEqual(domain_request.has_anything_else_text, None)
self.assertEqual(domain_request.has_cisa_representative, None) self.assertEqual(domain_request.has_cisa_representative, None)

View file

@ -366,7 +366,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
or self.domain_request.no_other_contacts_rationale is not None or self.domain_request.no_other_contacts_rationale is not None
), ),
"additional_details": ( "additional_details": (
(self.domain_request.anything_else is not None and self.domain_request.cisa_representative_email) (self.domain_request.anything_else is not None and self.domain_request.has_cisa_representative)
or self.domain_request.is_policy_acknowledged is not None or self.domain_request.is_policy_acknowledged is not None
), ),
"requirements": self.domain_request.is_policy_acknowledged is not None, "requirements": self.domain_request.is_policy_acknowledged is not None,