diff --git a/src/api/tests/test_available.py b/src/api/tests/test_available.py
index 0529882f2..061b6274c 100644
--- a/src/api/tests/test_available.py
+++ b/src/api/tests/test_available.py
@@ -2,7 +2,6 @@
import json
-from django.core.exceptions import BadRequest
from django.contrib.auth import get_user_model
from django.test import TestCase, RequestFactory
@@ -85,8 +84,8 @@ class AvailableViewTest(TestCase):
bad_string = "blah!;"
request = self.factory.get(API_BASE_PATH + bad_string)
request.user = self.user
- with self.assertRaisesMessage(BadRequest, "Invalid"):
- available(request, domain=bad_string)
+ response = available(request, domain=bad_string)
+ self.assertFalse(json.loads(response.content)["available"])
class AvailableAPITest(TestCase):
@@ -108,9 +107,3 @@ class AvailableAPITest(TestCase):
with less_console_noise():
response = self.client.post(API_BASE_PATH + "nonsense")
self.assertEqual(response.status_code, 405)
-
- def test_available_bad_input(self):
- self.client.force_login(self.user)
- with less_console_noise():
- response = self.client.get(API_BASE_PATH + "blah!;")
- self.assertEqual(response.status_code, 400)
diff --git a/src/api/views.py b/src/api/views.py
index deaacf0c6..9d23dcf85 100644
--- a/src/api/views.py
+++ b/src/api/views.py
@@ -17,13 +17,13 @@ DOMAIN_FILE_URL = (
DOMAIN_API_MESSAGES = {
"required": "Enter the .gov domain you want. Don’t include “www” or “.gov.”"
- " For example, if you want www.city.gov, you would enter “city”"
- " (without the quotes).",
+ " For example, if you want www.city.gov, you would enter “city”"
+ " (without the quotes).",
"extra_dots": "Enter the .gov domain you want without any periods.",
"unavailable": "That domain isn’t available. Try entering another one."
- " Contact us if you need help coming up with a domain.",
+ " Contact us if you need help coming up with a domain.",
"invalid": "Enter a domain using only letters,"
- " numbers, or hyphens (though we don't recommend using hyphens).",
+ " numbers, or hyphens (though we don't recommend using hyphens).",
"success": "That domain is available!",
}
@@ -83,18 +83,15 @@ def available(request, domain=""):
Domain.string_could_be_domain(domain)
or Domain.string_could_be_domain(domain + ".gov")
):
- return JsonResponse({
- "available": False,
- "message": DOMAIN_API_MESSAGES["invalid"]
- })
+ return JsonResponse(
+ {"available": False, "message": DOMAIN_API_MESSAGES["invalid"]}
+ )
# a domain is available if it is NOT in the list of current domains
if in_domains(domain):
- return JsonResponse({
- "available": False,
- "message": DOMAIN_API_MESSAGES["unavailable"]
- })
+ return JsonResponse(
+ {"available": False, "message": DOMAIN_API_MESSAGES["unavailable"]}
+ )
else:
- return JsonResponse({
- "available": True,
- "message": DOMAIN_API_MESSAGES["success"]
- })
+ return JsonResponse(
+ {"available": True, "message": DOMAIN_API_MESSAGES["success"]}
+ )
diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py
index b1033a52d..0b7f00e69 100644
--- a/src/registrar/forms/application_wizard.py
+++ b/src/registrar/forms/application_wizard.py
@@ -416,6 +416,7 @@ CurrentSitesFormSet = forms.formset_factory(
formset=BaseCurrentSitesFormSet,
)
+
class AlternativeDomainForm(RegistrarForm):
def clean_alternative_domain(self):
"""Validation code for domain names."""
@@ -423,19 +424,23 @@ class AlternativeDomainForm(RegistrarForm):
requested = self.cleaned_data.get("alternative_domain", None)
validated = Domain.validate(requested, blank_ok=True)
except errors.ExtraDotsError:
- raise forms.ValidationError(code="extra_dots")
+ raise forms.ValidationError(
+ DOMAIN_API_MESSAGES["extra_dots"], code="extra_dots"
+ )
except errors.DomainUnavailableError:
- raise forms.ValidationError(code="unavailable")
+ raise forms.ValidationError(
+ DOMAIN_API_MESSAGES["unavailable"], code="unavailable"
+ )
except ValueError:
- raise forms.ValidationError(code="invalid")
+ raise forms.ValidationError(DOMAIN_API_MESSAGES["invalid"], code="invalid")
return validated
alternative_domain = forms.CharField(
required=False,
label="Alternative domain",
- error_messages=DOMAIN_API_MESSAGES
)
+
class BaseAlternativeDomainFormSet(RegistrarFormSet):
JOIN = "alternative_domains"
@@ -508,19 +513,22 @@ class DotGovDomainForm(RegistrarForm):
requested = self.cleaned_data.get("requested_domain", None)
validated = Domain.validate(requested)
except errors.BlankValueError:
- raise forms.ValidationError(code="required")
+ raise forms.ValidationError(
+ DOMAIN_API_MESSAGES["required"], code="required"
+ )
except errors.ExtraDotsError:
- raise forms.ValidationError(code="extra_dots")
+ raise forms.ValidationError(
+ DOMAIN_API_MESSAGES["extra_dots"], code="extra_dots"
+ )
except errors.DomainUnavailableError:
- raise forms.ValidationError(code="unavailable")
+ raise forms.ValidationError(
+ DOMAIN_API_MESSAGES["unavailable"], code="unavailable"
+ )
except ValueError:
- raise forms.ValidationError(code="invalid")
+ raise forms.ValidationError(DOMAIN_API_MESSAGES["invalid"], code="invalid")
return validated
- requested_domain = forms.CharField(
- label="What .gov domain do you want?",
- error_messages=DOMAIN_API_MESSAGES
- )
+ requested_domain = forms.CharField(label="What .gov domain do you want?")
class PurposeForm(RegistrarForm):
diff --git a/src/registrar/templates/application_anything_else.html b/src/registrar/templates/application_anything_else.html
index aba7ded8a..0ed6bd2ca 100644
--- a/src/registrar/templates/application_anything_else.html
+++ b/src/registrar/templates/application_anything_else.html
@@ -7,7 +7,6 @@
{% block form_fields %}
- {% csrf_token %}
{% with add_label_class="usa-sr-only" attr_maxlength=500 %}
{% input_with_errors forms.0.anything_else %}
{% endwith %}
diff --git a/src/registrar/templates/application_authorizing_official.html b/src/registrar/templates/application_authorizing_official.html
index 3ef5c3892..10c5e71eb 100644
--- a/src/registrar/templates/application_authorizing_official.html
+++ b/src/registrar/templates/application_authorizing_official.html
@@ -21,7 +21,6 @@
{% block form_fields %}
- {% csrf_token %}