tests and linter fixes

This commit is contained in:
matthewswspence 2025-03-13 11:59:55 -05:00
parent 48d025019f
commit 09d92f6edc
No known key found for this signature in database
GPG key ID: FB458202A7852BA4
4 changed files with 106 additions and 22 deletions

View file

@ -3,6 +3,7 @@ from django.core.validators import MaxLengthValidator
from registrar.forms.utility.wizard_form_helper import BaseDeletableRegistrarForm, BaseYesNoForm
from registrar.models.contact import Contact
class ExecutiveNamingRequirementsYesNoForm(BaseYesNoForm, BaseDeletableRegistrarForm):
"""
Form for verifying if the domain request meets the Federal Executive Branch domain naming requirements.
@ -206,4 +207,4 @@ class FEBAnythingElseYesNoForm(BaseYesNoForm, BaseDeletableRegistrarForm):
"""Yes/no toggle for the anything else question on additional details"""
form_is_checked = property(lambda self: self.domain_request.has_anything_else_text) # type: ignore
field_name = "has_anything_else_text"
field_name = "has_anything_else_text"

View file

@ -53,18 +53,57 @@
{% endfor %}
</ul>
{% endif %}
{% if requires_feb_questions %}
<h4>Meets Naming Requirements</h4>
<p class="margin-y-0">{{domain_request.feb_naming_requirements|yesno:"Yes,No"}}</p>
{% if not domain_request.feb_naming_requirements %}
<p class="margin-y-0">{{domain_request.feb_naming_requirements_details}}</p>
{% endif %}
{% endif %}
{% endif %}
{% if step == Step.PURPOSE %}
{% with title=form_titles|get_item:step value=domain_request.purpose|default:"<span class='text-bold text-secondary-dark'>Incomplete</span>"|safe %}
{% include "includes/summary_item.html" with title=title value=value heading_level=heading_level editable=is_editable edit_link=domain_request_url %}
{% endwith %}
{% if requires_feb_questions %}
<h4>Purpose</h4>
{% if domain_request.feb_purpose_choice == "website" %}
<p class="margin-y-0">Used for a new website</p>
{% elif domain_request.feb_purpose_choice == "redirect" %}
<p class="margin-y-0">Used as a redirect for an existing website</p>
{% else %}
<p class="margin-y-0">Not for a website</p>
{% endif %}
<p class="margin-y-0">{{domain_request.purpose}}</p>
<h4>Target Time Frame</h4>
{% if domain_request.has_timeframe %}
<p class="margin-y-0">{{domain_request.time_frame_details}}</p>
{% else %}
<p class="margin-y-0">No</p>
{% endif %}
<h4>Interagency Initiative</h4>
{% if domain_request.is_interagency_initiative %}
<p class="margin-y-0">{{domain_request.interagency_initiative_details}}</p>
{% else %}
<p class="margin-y-0">No</p>
{% endif %}
{% endif %}
{% endif %}
{% if step == Step.ADDITIONAL_DETAILS %}
{% with title=form_titles|get_item:step value=domain_request.anything_else|default:"None" %}
{% include "includes/summary_item.html" with title=title value=value heading_level=heading_level editable=is_editable edit_link=domain_request_url %}
{% endwith %}
{% if requires_feb_questions %}
<h4>EOP Stakeholder</h4>
{% if domain_request.working_with_eop %}
<p class="margin-y-0">{{domain_request.eop_contact.first_name}} {{domain_request.eop_contact.last_name}}</p>
<p class="margin-y-0">{{domain_request.eop_contact.email}}</p>
{% else %}
<p class="margin-y-0">No</p>
{% endif %}
{% endif %}
{% endif %}
{% if step == Step.REQUIREMENTS %}

View file

@ -2615,8 +2615,8 @@ class DomainRequestTests(TestWithUser, WebTest):
domain_form = dotgov_page.forms[0]
domain = "test.gov"
domain_form["dotgov_domain-requested_domain"] = domain
domain_form["dotgov_domain-feb_naming_requirements"] = "True"
domain_form["dotgov_domain-feb_naming_requirements_details"] = "test"
domain_form["dotgov_domain-feb_naming_requirements"] = "False"
domain_form["dotgov_domain-feb_naming_requirements_details"] = "Because this is a test"
with patch(
"registrar.forms.domain_request_wizard.DotGovDomainForm.clean_requested_domain", return_value=domain
): # noqa
@ -2631,11 +2631,11 @@ class DomainRequestTests(TestWithUser, WebTest):
purpose_form = purpose_page.forms[0]
purpose_form["purpose-feb_purpose_choice"] = "redirect"
purpose_form["purpose-purpose"] = "test"
purpose_form["purpose-purpose"] = "testPurpose123"
purpose_form["purpose-has_timeframe"] = "True"
purpose_form["purpose-time_frame_details"] = "test"
purpose_form["purpose-time_frame_details"] = "1/2/2025 - 1/2/2026"
purpose_form["purpose-is_interagency_initiative"] = "True"
purpose_form["purpose-interagency_initiative_details"] = "test"
purpose_form["purpose-interagency_initiative_details"] = "FakeInteragencyInitiative"
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
purpose_result = purpose_form.submit()
@ -2646,8 +2646,8 @@ class DomainRequestTests(TestWithUser, WebTest):
additional_details_form = additional_details_page.forms[0]
additional_details_form["portfolio_additional_details-working_with_eop"] = "True"
additional_details_form["portfolio_additional_details-first_name"] = "Testy"
additional_details_form["portfolio_additional_details-last_name"] = "Tester"
additional_details_form["portfolio_additional_details-first_name"] = "TesterFirstName"
additional_details_form["portfolio_additional_details-last_name"] = "TesterLastName"
additional_details_form["portfolio_additional_details-email"] = "testy@town.com"
additional_details_form["portfolio_additional_details-has_anything_else_text"] = "True"
additional_details_form["portfolio_additional_details-anything_else"] = "test"
@ -2659,6 +2659,16 @@ class DomainRequestTests(TestWithUser, WebTest):
requirements_page = additional_details_result.follow()
self.feb_requirements_page_tests(requirements_page)
requirements_form = requirements_page.forms[0]
requirements_form["requirements-is_policy_acknowledged"] = "True"
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
requirements_result = requirements_form.submit()
# ---- REVIEW PAGE ----
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
review_page = requirements_result.follow()
self.feb_review_page_tests(review_page)
def feb_purpose_page_tests(self, purpose_page):
self.assertContains(purpose_page, "What is the purpose of your requested domain?")
@ -2718,12 +2728,40 @@ class DomainRequestTests(TestWithUser, WebTest):
def feb_requirements_page_tests(self, requirements_page):
# Check for the 21st Century IDEA Act links
self.assertContains(requirements_page, "https://digital.gov/resources/delivering-digital-first-public-experience-act/")
self.assertContains(requirements_page, "https://bidenwhitehouse.gov/wp-content/uploads/2023/09/M-23-22-Delivering-a-Digital-First-Public-Experience.pdf")
self.assertContains(
requirements_page, "https://digital.gov/resources/delivering-digital-first-public-experience-act/"
)
self.assertContains(
requirements_page,
"https://bidenwhitehouse.gov/wp-content/uploads/2023/09/M-23-22-Delivering-a-Digital-First-Public-Experience.pdf",
)
# Check for the policy acknowledgement form
self.assertContains(requirements_page, "is_policy_acknowledged")
self.assertContains(requirements_page, "I read and understand the guidance outlined in the DOTGOV Act for operating a .gov domain.")
self.assertContains(
requirements_page,
"I read and understand the guidance outlined in the DOTGOV Act for operating a .gov domain.",
)
def feb_review_page_tests(self, review_page):
# Meets Naming Requirements
self.assertContains(review_page, "<h4>Meets Naming Requirements</h4>")
self.assertContains(review_page, "No")
self.assertContains(review_page, "Because this is a test")
# Purpose
self.assertContains(review_page, "<h4>Purpose</h4>")
self.assertContains(review_page, "Used as a redirect for an existing website")
self.assertContains(review_page, "testPurpose123")
# Target Time Frame
self.assertContains(review_page, "<h4>Target Time Frame</h4>")
self.assertContains(review_page, "1/2/2025 - 1/2/2026")
# Interagency Initiative
self.assertContains(review_page, "<h4>Interagency Initiative</h4>")
self.assertContains(review_page, "FakeInteragencyInitiative")
# EOP Stakeholder
self.assertContains(review_page, "<h4>EOP Stakeholder</h4>")
self.assertContains(review_page, "TesterFirstName TesterLastName")
self.assertContains(review_page, "testy@town.com")
@less_console_noise_decorator
def test_domain_request_formsets(self):

View file

@ -631,21 +631,23 @@ class PortfolioAdditionalDetails(DomainRequestWizard):
if not forms[0].is_valid():
# If the user isn't working with EOP, don't validate the EOP contact form
forms[1].mark_form_for_deletion()
eop_forms_valid = False
eop_forms_valid = False
if forms[0].cleaned_data.get("working_with_eop"):
eop_forms_valid = forms[1].is_valid()
else:
forms[1].mark_form_for_deletion()
forms[1].mark_form_for_deletion()
anything_else_forms_valid = True
if not forms[2].is_valid():
forms[3].mark_form_for_deletion()
anything_else_forms_valid = False
anything_else_forms_valid = False
if forms[2].cleaned_data.get("has_anything_else_text"):
forms[3].fields["anything_else"].required = True
forms[3].fields["anything_else"].error_messages["required"] = "Please provide additional details you'd like us to know. \
forms[3].fields["anything_else"].error_messages[
"required"
] = "Please provide additional details you'd like us to know. \
If you have nothing to add, select 'No'."
anything_else_forms_valid = forms[3].is_valid()
return (eop_forms_valid and anything_else_forms_valid)
anything_else_forms_valid = forms[3].is_valid()
return eop_forms_valid and anything_else_forms_valid
# Non-portfolio pages
@ -937,15 +939,19 @@ class Requirements(DomainRequestWizard):
# Override the get_forms method to set the policy acknowledgement label conditionally based on feb status
def get_forms(self, step=None, use_post=False, use_db=False, files=None):
forms_list = super().get_forms(step, use_post, use_db, files)
# Pass the is_federal context to the form
for form in forms_list:
if isinstance(form, forms.RequirementsForm):
if self.requires_feb_questions():
form.fields['is_policy_acknowledged'].label = "I read and understand the guidance outlined in the DOTGOV Act for operating a .gov domain." # noqa: E501
form.fields["is_policy_acknowledged"].label = (
"I read and understand the guidance outlined in the DOTGOV Act for operating a .gov domain." # noqa: E501
)
else:
form.fields['is_policy_acknowledged'].label = "I read and agree to the requirements for operating a .gov domain." # noqa: E501
form.fields["is_policy_acknowledged"].label = (
"I read and agree to the requirements for operating a .gov domain." # noqa: E501
)
return forms_list