Merge pull request #399 from dod-ccpo/hyphenate-names-#161325890
Update Alphabet validator to accept hyphens
This commit is contained in:
commit
778c029877
@ -3,7 +3,7 @@ from wtforms.fields import StringField, TextAreaField
|
|||||||
from wtforms.validators import Email, Optional
|
from wtforms.validators import Email, Optional
|
||||||
|
|
||||||
from .forms import ValidatedForm
|
from .forms import ValidatedForm
|
||||||
from .validators import Alphabet, PhoneNumber
|
from .validators import Name, PhoneNumber
|
||||||
|
|
||||||
|
|
||||||
class CCPOReviewForm(ValidatedForm):
|
class CCPOReviewForm(ValidatedForm):
|
||||||
@ -11,19 +11,13 @@ class CCPOReviewForm(ValidatedForm):
|
|||||||
"Instructions or comments",
|
"Instructions or comments",
|
||||||
description="Provide instructions or notes for additional information that is necessary to approve the request here. The requestor may then re-submit the updated request or initiate contact outside of AT-AT if further discussion is required. <strong>This message will be shared with the person making the JEDI request.</strong>.",
|
description="Provide instructions or notes for additional information that is necessary to approve the request here. The requestor may then re-submit the updated request or initiate contact outside of AT-AT if further discussion is required. <strong>This message will be shared with the person making the JEDI request.</strong>.",
|
||||||
)
|
)
|
||||||
fname_mao = StringField(
|
fname_mao = StringField("First Name (optional)", validators=[Optional(), Name()])
|
||||||
"First Name (optional)", validators=[Optional(), Alphabet()]
|
lname_mao = StringField("Last Name (optional)", validators=[Optional(), Name()])
|
||||||
)
|
|
||||||
lname_mao = StringField("Last Name (optional)", validators=[Optional(), Alphabet()])
|
|
||||||
email_mao = EmailField(
|
email_mao = EmailField(
|
||||||
"Mission Owner e-mail (optional)", validators=[Optional(), Email()]
|
"Mission Owner e-mail (optional)", validators=[Optional(), Email()]
|
||||||
)
|
)
|
||||||
phone_mao = TelField(
|
phone_mao = TelField(
|
||||||
"Mission Owner phone number (optional)", validators=[Optional(), PhoneNumber()]
|
"Mission Owner phone number (optional)", validators=[Optional(), PhoneNumber()]
|
||||||
)
|
)
|
||||||
fname_ccpo = StringField(
|
fname_ccpo = StringField("First Name (optional)", validators=[Optional(), Name()])
|
||||||
"First Name (optional)", validators=[Optional(), Alphabet()]
|
lname_ccpo = StringField("Last Name (optional)", validators=[Optional(), Name()])
|
||||||
)
|
|
||||||
lname_ccpo = StringField(
|
|
||||||
"Last Name (optional)", validators=[Optional(), Alphabet()]
|
|
||||||
)
|
|
||||||
|
@ -8,11 +8,11 @@ from .fields import SelectField
|
|||||||
from .forms import ValidatedForm
|
from .forms import ValidatedForm
|
||||||
from .data import SERVICE_BRANCHES
|
from .data import SERVICE_BRANCHES
|
||||||
|
|
||||||
from .validators import Alphabet, DateRange, PhoneNumber
|
from .validators import Name, DateRange, PhoneNumber
|
||||||
|
|
||||||
USER_FIELDS = {
|
USER_FIELDS = {
|
||||||
"first_name": StringField("First Name", validators=[Alphabet()]),
|
"first_name": StringField("First Name", validators=[Name()]),
|
||||||
"last_name": StringField("Last Name", validators=[Alphabet()]),
|
"last_name": StringField("Last Name", validators=[Name()]),
|
||||||
"email": EmailField(
|
"email": EmailField(
|
||||||
"E-mail Address",
|
"E-mail Address",
|
||||||
description="Enter your preferred contact e-mail address",
|
description="Enter your preferred contact e-mail address",
|
||||||
|
@ -50,13 +50,15 @@ def PhoneNumber(message="Please enter a valid 5 or 10 digit phone number."):
|
|||||||
return _is_phone_number
|
return _is_phone_number
|
||||||
|
|
||||||
|
|
||||||
def Alphabet(message="Please enter only letters."):
|
def Name(
|
||||||
def _alphabet(form, field):
|
message="This field accepts letters, numbers, commas, apostrophes, hyphens, and periods."
|
||||||
match = re.match(r"[A-Za-z]+", field.data)
|
):
|
||||||
|
def _name(form, field):
|
||||||
|
match = re.match(r"[\w \,\.\'\-]+", field.data)
|
||||||
if not match or match.group() != field.data:
|
if not match or match.group() != field.data:
|
||||||
raise ValidationError(message)
|
raise ValidationError(message)
|
||||||
|
|
||||||
return _alphabet
|
return _name
|
||||||
|
|
||||||
|
|
||||||
def ListItemRequired(message="Please provide at least one.", empty_values=("", None)):
|
def ListItemRequired(message="Please provide at least one.", empty_values=("", None)):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from wtforms.validators import ValidationError
|
from wtforms.validators import ValidationError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from atst.forms.validators import Alphabet, IsNumber, PhoneNumber, ListItemsUnique
|
from atst.forms.validators import Name, IsNumber, PhoneNumber, ListItemsUnique
|
||||||
|
|
||||||
|
|
||||||
class TestIsNumber:
|
class TestIsNumber:
|
||||||
@ -38,16 +38,19 @@ class TestPhoneNumber:
|
|||||||
validator(dummy_form, dummy_field)
|
validator(dummy_form, dummy_field)
|
||||||
|
|
||||||
|
|
||||||
class TestAlphabet:
|
class TestName:
|
||||||
@pytest.mark.parametrize("valid", ["a", "abcde"])
|
@pytest.mark.parametrize("valid", ["a", "abcde", "hi mark", "cloud9", "niña"])
|
||||||
def test_Alphabet_accepts_letters(self, valid, dummy_form, dummy_field):
|
def test_Name_accepts_letters(self, valid, dummy_form, dummy_field):
|
||||||
validator = Alphabet()
|
validator = Name()
|
||||||
dummy_field.data = valid
|
dummy_field.data = valid
|
||||||
validator(dummy_form, dummy_field)
|
validator(dummy_form, dummy_field)
|
||||||
|
|
||||||
@pytest.mark.parametrize("invalid", ["", "hi mark", "cloud9"])
|
@pytest.mark.parametrize(
|
||||||
def test_Alphabet_rejects_non_letters(self, invalid, dummy_form, dummy_field):
|
"invalid",
|
||||||
validator = Alphabet()
|
["", "/my name", ":-)", "Name&Name", "Ke$ha", "A^Name", "#yourvalidname"],
|
||||||
|
)
|
||||||
|
def test_Name_rejects_invalid_characters(self, invalid, dummy_form, dummy_field):
|
||||||
|
validator = Name()
|
||||||
dummy_field.data = invalid
|
dummy_field.data = invalid
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
validator(dummy_form, dummy_field)
|
validator(dummy_form, dummy_field)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user