From 659fff322e38a3e766a4a6318b524ae46dca5a24 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:04:13 -0700 Subject: [PATCH] Add unit tests --- src/registrar/forms/application_wizard.py | 14 ++++++++++---- src/registrar/models/utility/domain_helper.py | 8 ++------ src/registrar/tests/test_forms.py | 10 ++++++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/registrar/forms/application_wizard.py b/src/registrar/forms/application_wizard.py index e318ee5aa..34bfb1731 100644 --- a/src/registrar/forms/application_wizard.py +++ b/src/registrar/forms/application_wizard.py @@ -2,6 +2,7 @@ from __future__ import annotations # allows forward references in annotations from itertools import zip_longest import logging from typing import Callable +from api.views import DOMAIN_API_MESSAGES from phonenumber_field.formfields import PhoneNumberField # type: ignore from django import forms @@ -384,8 +385,8 @@ class AlternativeDomainForm(RegistrarForm): """Validation code for domain names.""" requested = self.cleaned_data.get("alternative_domain", None) validated, _ = DraftDomain.validate_and_handle_errors( - domain=requested, - return_type=ValidationReturnType.FORM_VALIDATION_ERROR, + domain=requested, + return_type=ValidationReturnType.FORM_VALIDATION_ERROR, blank_ok=True, ) return validated @@ -464,12 +465,17 @@ class DotGovDomainForm(RegistrarForm): """Validation code for domain names.""" requested = self.cleaned_data.get("requested_domain", None) validated, _ = DraftDomain.validate_and_handle_errors( - domain=requested, + domain=requested, return_type=ValidationReturnType.FORM_VALIDATION_ERROR, ) return validated - requested_domain = forms.CharField(label="What .gov domain do you want?") + requested_domain = forms.CharField( + label="What .gov domain do you want?", + error_messages={ + "required": DOMAIN_API_MESSAGES["required"], + }, + ) class PurposeForm(RegistrarForm): diff --git a/src/registrar/models/utility/domain_helper.py b/src/registrar/models/utility/domain_helper.py index 5647fe49e..818473f2f 100644 --- a/src/registrar/models/utility/domain_helper.py +++ b/src/registrar/models/utility/domain_helper.py @@ -94,15 +94,11 @@ class DomainHelper: error_type = type(error) # Generate the response based on the error code and return type - response = DomainHelper._return_form_error_or_json_response( - return_type, code=error_map.get(error_type) - ) + response = DomainHelper._return_form_error_or_json_response(return_type, code=error_map.get(error_type)) else: # For form validation, we do not need to display the success message if return_type != ValidationReturnType.FORM_VALIDATION_ERROR: - response = DomainHelper._return_form_error_or_json_response( - return_type, code="success", available=True - ) + response = DomainHelper._return_form_error_or_json_response(return_type, code="success", available=True) # Return the validated domain and the response (either error or success) return (validated, response) diff --git a/src/registrar/tests/test_forms.py b/src/registrar/tests/test_forms.py index 0187a7636..a49257b75 100644 --- a/src/registrar/tests/test_forms.py +++ b/src/registrar/tests/test_forms.py @@ -2,7 +2,6 @@ import json from django.test import TestCase, RequestFactory -from django.urls import reverse from api.views import available from registrar.forms.application_wizard import ( @@ -92,7 +91,12 @@ class TestFormValidation(MockEppLib): "Enter a domain using only letters, numbers, " "or hyphens (though we don't recommend using hyphens).", ), # required - ("", "Enter the .gov domain you want. Don’t include “www” or “.gov.”"), + ( + "", + "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).", + ), # unavailable ( "whitehouse.gov", @@ -143,8 +147,6 @@ class TestFormValidation(MockEppLib): "underscores_forever", "Enter a domain using only letters, numbers, " "or hyphens (though we don't recommend using hyphens).", ), - # required - ("", "Enter the .gov domain you want. Don’t include “www” or “.gov.”"), # unavailable ( "whitehouse.gov",