mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 01:11:55 +02:00
Unit testing
This commit is contained in:
parent
9d759d31c3
commit
52718b9e04
4 changed files with 124 additions and 26 deletions
|
@ -42,7 +42,6 @@ legend.float-left-tablet + button.float-right-tablet {
|
|||
/* Custom style for disabled inputs */
|
||||
// TODO - UPDATE THIS!
|
||||
.usa-input:disabled, .usa-select:disabled, .usa-textarea:disabled {
|
||||
background-color: #f0f0f0;
|
||||
color: #5b616b;
|
||||
border-color: #5b616b;
|
||||
background-color: --body-fg;
|
||||
color: --close-button-hover-bg;
|
||||
}
|
||||
|
|
|
@ -243,15 +243,28 @@ class AuthorizingOfficialContactForm(ContactForm):
|
|||
"required": "Enter an email address in the required format, like name@example.com."
|
||||
}
|
||||
|
||||
# TODO - uswds text fields dont have disabled styling??
|
||||
# All fields should be disabled if the domain is federal or tribal
|
||||
if disable_fields:
|
||||
self._mass_disable_fields()
|
||||
self._mass_disable_fields(disable_required=True, disable_maxlength=True)
|
||||
|
||||
def _mass_disable_fields(self):
|
||||
"""Given all available fields, invoke .disabled = True on them"""
|
||||
def _mass_disable_fields(self, disable_required=False, disable_maxlength=False):
|
||||
"""
|
||||
Given all available fields, invoke .disabled = True on them.
|
||||
|
||||
disable_required: bool -> invokes .required = False on each field.
|
||||
disable_maxlength: bool -> pops "maxlength" from each field.
|
||||
"""
|
||||
for field in self.fields.values():
|
||||
field.disabled = True
|
||||
|
||||
if disable_required:
|
||||
# if a field is disabled, it can't be required
|
||||
field.required = False
|
||||
|
||||
if disable_maxlength:
|
||||
# Remove the maxlength dialog
|
||||
if "maxlength" in field.widget.attrs:
|
||||
field.widget.attrs.pop('maxlength', None)
|
||||
|
||||
|
||||
def save(self, commit=True):
|
||||
|
@ -371,17 +384,11 @@ class DomainOrgNameAddressForm(forms.ModelForm):
|
|||
is_federal = self.instance.organization_type == DomainApplication.OrganizationChoices.FEDERAL
|
||||
is_tribal = self.instance.organization_type == DomainApplication.OrganizationChoices.TRIBAL
|
||||
|
||||
# (Q) Should required = False be set here?
|
||||
# These fields should not be None. If they are,
|
||||
# it seems like an analyst should intervene?
|
||||
|
||||
# TODO - maybe consider adding a modal on these fields on hover
|
||||
# ALSO TODO - uswds text fields dont have disabled styling??
|
||||
if is_federal:
|
||||
self.fields['federal_agency'].disabled = True
|
||||
self.fields["federal_agency"].disabled = True
|
||||
elif is_tribal:
|
||||
self.fields['organization_name'].disabled = True
|
||||
|
||||
self.fields["organization_name"].disabled = True
|
||||
|
||||
def save(self, commit=True):
|
||||
"""Override the save() method of the BaseModelForm."""
|
||||
if self.has_changed():
|
||||
|
@ -412,7 +419,6 @@ class DomainOrgNameAddressForm(forms.ModelForm):
|
|||
return old_value == new_value
|
||||
|
||||
|
||||
|
||||
class DomainDnssecForm(forms.Form):
|
||||
"""Form for enabling and disabling dnssec"""
|
||||
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
{% if organization_type == "federal" or organization_type == "tribal" %}
|
||||
<p>
|
||||
The authorizing official for your organization can’t be updated here.
|
||||
The authorizing official for your organization can’t be updated here.
|
||||
To suggest an update, email <a href="mailto:help@get.gov" class="usa-link">help@get.gov</a>.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
{% include "includes/required_fields.html" %}
|
||||
{% endif %}
|
||||
|
||||
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
|
||||
{% csrf_token %}
|
||||
|
@ -32,10 +32,8 @@
|
|||
|
||||
{% input_with_errors form.email %}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="usa-button"
|
||||
>Save</button>
|
||||
</form>
|
||||
|
||||
{% if organization_type != "federal" and organization_type != "tribal" %}
|
||||
<button type="submit" class="usa-button">Save</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %} {# domain_content #}
|
||||
|
|
|
@ -1087,6 +1087,101 @@ class TestDomainOrganization(TestDomainOverview):
|
|||
|
||||
self.assertContains(success_result_page, "Not igorville")
|
||||
self.assertContains(success_result_page, "Faketown")
|
||||
|
||||
def test_domain_org_name_address_form_tribal(self):
|
||||
"""
|
||||
Submitting a change to organization_name is blocked for tribal domains
|
||||
"""
|
||||
# Set the current domain to a tribal organization with a preset value.
|
||||
# Save first, so we can test if saving is unaffected (it should be).
|
||||
tribal_org_type = DomainInformation.OrganizationChoices.TRIBAL
|
||||
self.domain_information.organization_type = tribal_org_type
|
||||
self.domain_information.save()
|
||||
try:
|
||||
# Add an org name
|
||||
self.domain_information.organization_name = "Town of Igorville"
|
||||
self.domain_information.save()
|
||||
except ValueError as err:
|
||||
self.fail(f"A ValueError was caught during the test: {err}")
|
||||
|
||||
self.assertEqual(self.domain_information.organization_type, tribal_org_type)
|
||||
|
||||
org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id}))
|
||||
print(f"what is the org name page? {org_name_page}")
|
||||
|
||||
form = org_name_page.forms[0]
|
||||
# Check the value of the input field
|
||||
organization_name_input = form.fields["organization_name"][0]
|
||||
self.assertEqual(organization_name_input.value, "Town of Igorville")
|
||||
|
||||
# Check if the input field is disabled
|
||||
self.assertTrue("disabled" in organization_name_input.attrs)
|
||||
self.assertEqual(organization_name_input.attrs.get("disabled"), "")
|
||||
|
||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||
|
||||
org_name_page.form["organization_name"] = "Not igorville"
|
||||
org_name_page.form["city"] = "Faketown"
|
||||
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
|
||||
# Make the change. The org name should be unchanged, but city should be modifiable.
|
||||
success_result_page = org_name_page.form.submit()
|
||||
self.assertEqual(success_result_page.status_code, 200)
|
||||
|
||||
# Check for the old and new value
|
||||
self.assertContains(success_result_page, "Town of Igorville")
|
||||
self.assertNotContains(success_result_page, "Not igorville")
|
||||
|
||||
# Check for the value we want to update
|
||||
self.assertContains(success_result_page, "Faketown")
|
||||
|
||||
def test_domain_org_name_address_form_federal(self):
|
||||
"""
|
||||
Submitting a change to federal_agency is blocked for federal domains
|
||||
"""
|
||||
# Set the current domain to a tribal organization with a preset value.
|
||||
# Save first, so we can test if saving is unaffected (it should be).
|
||||
federal_org_type = DomainInformation.OrganizationChoices.FEDERAL
|
||||
self.domain_information.organization_type = federal_org_type
|
||||
self.domain_information.save()
|
||||
try:
|
||||
# Add a federal agency. Defined as a tuple since this list may change order.
|
||||
self.domain_information.federal_agency = ("AMTRAK", "AMTRAK")
|
||||
self.domain_information.save()
|
||||
except ValueError as err:
|
||||
self.fail(f"A ValueError was caught during the test: {err}")
|
||||
|
||||
self.assertEqual(self.domain_information.organization_type, federal_org_type)
|
||||
|
||||
org_name_page = self.app.get(reverse("domain-org-name-address", kwargs={"pk": self.domain.id}))
|
||||
|
||||
form = org_name_page.forms[0]
|
||||
# Check the value of the input field
|
||||
federal_agency_input = form.fields["federal_agency"][0]
|
||||
self.assertEqual(federal_agency_input.value, "AMTRAK")
|
||||
|
||||
# Check if the input field is disabled
|
||||
self.assertTrue("disabled" in federal_agency_input.attrs)
|
||||
self.assertEqual(federal_agency_input.attrs.get("disabled"), "")
|
||||
|
||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||
|
||||
org_name_page.form["organization_name"] = "Not igorville"
|
||||
org_name_page.form["city"] = "Faketown"
|
||||
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
|
||||
# Make the change. The org name should be unchanged, but city should be modifiable.
|
||||
success_result_page = org_name_page.form.submit()
|
||||
self.assertEqual(success_result_page.status_code, 200)
|
||||
|
||||
# Check for the old and new value
|
||||
self.assertContains(success_result_page, "Town of Igorville")
|
||||
self.assertNotContains(success_result_page, "Not igorville")
|
||||
|
||||
# Check for the value we want to update
|
||||
self.assertContains(success_result_page, "Faketown")
|
||||
|
||||
|
||||
class TestDomainContactInformation(TestDomainOverview):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue