mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 10:29:23 +02:00
fixed unit tests (still need to rethink how to handle deletion of CISA rep contacts)
This commit is contained in:
parent
d9cc947f6e
commit
7dc9dba833
6 changed files with 41 additions and 27 deletions
|
@ -1376,7 +1376,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
"authorizing_official",
|
||||
"other_contacts",
|
||||
"no_other_contacts_rationale",
|
||||
"cisa_representative_email",
|
||||
"cisa_representative",
|
||||
]
|
||||
},
|
||||
),
|
||||
|
@ -1452,7 +1452,7 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
|||
"no_other_contacts_rationale",
|
||||
"anything_else",
|
||||
"is_policy_acknowledged",
|
||||
"cisa_representative_email",
|
||||
"cisa_representative",
|
||||
]
|
||||
autocomplete_fields = [
|
||||
"approved_domain",
|
||||
|
|
|
@ -649,14 +649,10 @@ class NoOtherContactsForm(BaseDeletableRegistrarForm):
|
|||
class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
||||
JOIN = "cisa_representative"
|
||||
|
||||
logger.debug("GETTING CISA REP")
|
||||
|
||||
def to_database(self, obj):
|
||||
logger.debug("SAVING CISA REP")
|
||||
if not self.is_valid():
|
||||
return
|
||||
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 exists in the database and is not joined to other entities
|
||||
super().to_database(contact)
|
||||
|
@ -665,7 +661,6 @@ class CisaRepresentativeForm(BaseDeletableRegistrarForm):
|
|||
# in either case, create a new contact and update it
|
||||
contact = Contact()
|
||||
super().to_database(contact)
|
||||
logger.debug("NEW REP: %s" % contact)
|
||||
obj.cisa_representative = contact
|
||||
obj.save()
|
||||
|
||||
|
|
|
@ -812,6 +812,7 @@ def completed_domain_request(
|
|||
has_alternative_gov_domain=True,
|
||||
has_about_your_organization=True,
|
||||
has_anything_else=True,
|
||||
has_cisa_representative=True,
|
||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||
user=False,
|
||||
submitter=False,
|
||||
|
@ -893,6 +894,13 @@ def completed_domain_request(
|
|||
domain_request.current_websites.add(current)
|
||||
if has_alternative_gov_domain:
|
||||
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
|
||||
|
||||
|
|
|
@ -2263,7 +2263,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
"no_other_contacts_rationale",
|
||||
"anything_else",
|
||||
"has_anything_else_text",
|
||||
"cisa_representative_email",
|
||||
"cisa_representative",
|
||||
"has_cisa_representative",
|
||||
"is_policy_acknowledged",
|
||||
"submission_date",
|
||||
|
@ -2296,7 +2296,7 @@ class TestDomainRequestAdmin(MockEppLib):
|
|||
"no_other_contacts_rationale",
|
||||
"anything_else",
|
||||
"is_policy_acknowledged",
|
||||
"cisa_representative_email",
|
||||
"cisa_representative",
|
||||
]
|
||||
|
||||
self.assertEqual(readonly_fields, expected_fields)
|
||||
|
|
|
@ -369,7 +369,9 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
|
||||
additional_details_form["additional_details-has_cisa_representative"] = "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."
|
||||
|
||||
# test next button
|
||||
|
@ -377,7 +379,9 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
additional_details_result = additional_details_form.submit()
|
||||
# validate that data from this step are being saved
|
||||
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.")
|
||||
# the post request should return a redirect to the next form in
|
||||
# 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
|
||||
anything_else"""
|
||||
|
||||
domain_request = completed_domain_request(user=self.user, has_anything_else=True)
|
||||
domain_request.cisa_representative_email = "test@igorville.gov"
|
||||
domain_request = completed_domain_request(user=self.user, has_anything_else=True, has_cisa_representative=True)
|
||||
domain_request.anything_else = "1234"
|
||||
domain_request.save()
|
||||
|
||||
|
@ -867,12 +870,11 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
"""On the Additional details page, the form preselects "no" when has_cisa_representative
|
||||
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.
|
||||
# This means that we should expect this to correlate with the no button.
|
||||
domain_request.has_anything_else_text = False
|
||||
domain_request.has_cisa_representative = False
|
||||
domain_request.save()
|
||||
|
||||
# prime the form by visiting /edit
|
||||
|
@ -891,7 +893,7 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
|
||||
# Check the cisa representative yes/no field
|
||||
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
|
||||
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,
|
||||
the domain request's data gets wiped when submitted"""
|
||||
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()
|
||||
|
||||
# Make sure we have the data we need for the test
|
||||
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
|
||||
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
|
||||
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
|
||||
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):
|
||||
"""When a user submits the Additional Details form,
|
||||
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
|
||||
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
|
||||
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
|
||||
additional_details_form["additional_details-has_cisa_representative"] = "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"
|
||||
|
||||
# Submit the form
|
||||
|
@ -992,14 +1000,16 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
domain_request = DomainRequest.objects.get(requested_domain__name="cisareps.gov")
|
||||
|
||||
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_anything_else_text, True)
|
||||
|
||||
def test_if_cisa_representative_yes_no_form_is_yes_then_field_is_required(self):
|
||||
"""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
|
||||
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.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):
|
||||
"""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):
|
||||
"""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"""
|
||||
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_cisa_representative, None)
|
||||
|
|
|
@ -366,7 +366,7 @@ class DomainRequestWizard(DomainRequestWizardPermissionView, TemplateView):
|
|||
or self.domain_request.no_other_contacts_rationale is not None
|
||||
),
|
||||
"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
|
||||
),
|
||||
"requirements": self.domain_request.is_policy_acknowledged is not None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue