mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 09:43:33 +02:00
Add unit tests
This commit is contained in:
parent
cdf46044d7
commit
659fff322e
3 changed files with 18 additions and 14 deletions
|
@ -2,6 +2,7 @@ from __future__ import annotations # allows forward references in annotations
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
import logging
|
import logging
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
from api.views import DOMAIN_API_MESSAGES
|
||||||
from phonenumber_field.formfields import PhoneNumberField # type: ignore
|
from phonenumber_field.formfields import PhoneNumberField # type: ignore
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -469,7 +470,12 @@ class DotGovDomainForm(RegistrarForm):
|
||||||
)
|
)
|
||||||
return validated
|
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):
|
class PurposeForm(RegistrarForm):
|
||||||
|
|
|
@ -94,15 +94,11 @@ class DomainHelper:
|
||||||
error_type = type(error)
|
error_type = type(error)
|
||||||
|
|
||||||
# Generate the response based on the error code and return type
|
# Generate the response based on the error code and return type
|
||||||
response = DomainHelper._return_form_error_or_json_response(
|
response = DomainHelper._return_form_error_or_json_response(return_type, code=error_map.get(error_type))
|
||||||
return_type, code=error_map.get(error_type)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# For form validation, we do not need to display the success message
|
# For form validation, we do not need to display the success message
|
||||||
if return_type != ValidationReturnType.FORM_VALIDATION_ERROR:
|
if return_type != ValidationReturnType.FORM_VALIDATION_ERROR:
|
||||||
response = DomainHelper._return_form_error_or_json_response(
|
response = DomainHelper._return_form_error_or_json_response(return_type, code="success", available=True)
|
||||||
return_type, code="success", available=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Return the validated domain and the response (either error or success)
|
# Return the validated domain and the response (either error or success)
|
||||||
return (validated, response)
|
return (validated, response)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import TestCase, RequestFactory
|
||||||
from django.urls import reverse
|
|
||||||
from api.views import available
|
from api.views import available
|
||||||
|
|
||||||
from registrar.forms.application_wizard import (
|
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).",
|
"Enter a domain using only letters, numbers, " "or hyphens (though we don't recommend using hyphens).",
|
||||||
),
|
),
|
||||||
# required
|
# 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
|
# unavailable
|
||||||
(
|
(
|
||||||
"whitehouse.gov",
|
"whitehouse.gov",
|
||||||
|
@ -143,8 +147,6 @@ class TestFormValidation(MockEppLib):
|
||||||
"underscores_forever",
|
"underscores_forever",
|
||||||
"Enter a domain using only letters, numbers, " "or hyphens (though we don't recommend using hyphens).",
|
"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
|
# unavailable
|
||||||
(
|
(
|
||||||
"whitehouse.gov",
|
"whitehouse.gov",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue