mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-10 06:24:45 +02:00
Add form test and fix linting/test merge errors
This commit is contained in:
parent
59c67a70d2
commit
d4ac5d92f1
4 changed files with 27 additions and 40 deletions
|
@ -121,7 +121,6 @@ class RegistrarFormSet(forms.BaseFormSet):
|
|||
# (likely a client-side error or an attempt at data tampering)
|
||||
|
||||
for db_obj, post_data in zip_longest(query, self.forms, fillvalue=None):
|
||||
|
||||
cleaned = post_data.cleaned_data if post_data is not None else {}
|
||||
|
||||
# matching database object exists, update it
|
||||
|
@ -177,9 +176,17 @@ class TribalGovernmentForm(RegistrarForm):
|
|||
|
||||
def clean(self):
|
||||
"""Needs to be either state or federally recognized."""
|
||||
if not (self.cleaned_data["federally_recognized_tribe"] or
|
||||
self.cleaned_data["state_recognized_tribe"]):
|
||||
raise forms.ValidationError("Only tribes recognized by the U.S. federal government or by a U.S. state government are eligible for .gov domains.", code="invalid")
|
||||
if not (
|
||||
self.cleaned_data["federally_recognized_tribe"]
|
||||
or self.cleaned_data["state_recognized_tribe"]
|
||||
):
|
||||
raise forms.ValidationError(
|
||||
"Only tribes recognized by the U.S. federal government or by a U.S."
|
||||
" state government are eligible for .gov domains. Please email"
|
||||
" registrar@dotgov.gov to tell us more about your tribe and why you"
|
||||
" want a .gov domain.",
|
||||
code="invalid",
|
||||
)
|
||||
|
||||
|
||||
class OrganizationFederalForm(RegistrarForm):
|
||||
|
|
|
@ -11,6 +11,7 @@ from registrar.forms.application_wizard import (
|
|||
OtherContactsForm,
|
||||
SecurityEmailForm,
|
||||
RequirementsForm,
|
||||
TribalGovernmentForm,
|
||||
)
|
||||
|
||||
|
||||
|
@ -150,3 +151,15 @@ class TestFormValidation(TestCase):
|
|||
" registering and operating .gov domains."
|
||||
],
|
||||
)
|
||||
|
||||
def test_tribal_government_unrecognized(self):
|
||||
"""Not state or federally recognized is an error."""
|
||||
form = TribalGovernmentForm(
|
||||
data={"state_recognized": False, "federally_recognized": False}
|
||||
)
|
||||
self.assertTrue(
|
||||
any(
|
||||
"Please email registrar@dotgov.gov" in error
|
||||
for error in form.non_field_errors()
|
||||
)
|
||||
)
|
||||
|
|
|
@ -743,23 +743,6 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
|
||||
def test_application_tribal_government(self):
|
||||
"""Tribal organizations have to answer an additional question."""
|
||||
type_form = type_page.form
|
||||
type_form[
|
||||
"organization_type-organization_type"
|
||||
] = DomainApplication.OrganizationChoices.TRIBAL
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
type_result = type_page.form.submit()
|
||||
# the tribal government page comes immediately afterwards
|
||||
self.assertIn("/tribal_government", type_result.headers["Location"])
|
||||
# follow first redirect
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
tribal_government_page = type_result.follow()
|
||||
|
||||
# and the step is on the sidebar list.
|
||||
self.assertContains(tribal_government_page, self.TITLES[Step.TRIBAL_GOVERNMENT])
|
||||
|
||||
def test_application_tribal_explanation(self):
|
||||
"""Unrecognized tribes have to answer an additional question."""
|
||||
type_page = self.app.get(reverse("application:")).follow()
|
||||
# django-webtest does not handle cookie-based sessions well because it keeps
|
||||
# resetting the session key on each new request, thus destroying the concept
|
||||
|
@ -778,22 +761,8 @@ class DomainApplicationTests(TestWithUser, WebTest):
|
|||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
tribal_government_page = type_result.follow()
|
||||
|
||||
# Enter a tribe name but don't check either state or federal recognition
|
||||
tribal_government_page.form["tribal_government-tribe_name"] = "Tribe name"
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
tribal_government_result = tribal_government_page.form.submit()
|
||||
|
||||
# should be a redirect to tribal_more_information
|
||||
self.assertIn("/tribal_more_information", tribal_government_result.headers["Location"])
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
tribal_more_information_page = tribal_government_result.follow()
|
||||
|
||||
# put an explanation and submit
|
||||
tribal_more_information_page.form["tribal_more_information-more_organization_information"] = "Some explanation"
|
||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||
result = tribal_more_information_page.form.submit()
|
||||
# result should be a success
|
||||
self.assertEqual(result.status_code, 200)
|
||||
# and the step is on the sidebar list.
|
||||
self.assertContains(tribal_government_page, self.TITLES[Step.TRIBAL_GOVERNMENT])
|
||||
|
||||
def test_application_ao_dynamic_text(self):
|
||||
type_page = self.app.get(reverse("application:")).follow()
|
||||
|
|
|
@ -94,9 +94,7 @@ class ApplicationWizard(LoginRequiredMixin, TemplateView):
|
|||
Step.ORGANIZATION_FEDERAL: lambda w: w.from_model(
|
||||
"show_organization_federal", False
|
||||
),
|
||||
Step.TRIBAL_GOVERNMENT: lambda w: w.from_model(
|
||||
"show_tribal_government", False
|
||||
),
|
||||
Step.TRIBAL_GOVERNMENT: lambda w: w.from_model("show_tribal_government", False),
|
||||
Step.ORGANIZATION_ELECTION: lambda w: w.from_model(
|
||||
"show_organization_election", False
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue