test: validate name

This commit is contained in:
Ankush Menat 2022-08-14 14:00:48 +05:30 committed by Ankush Menat
parent 26bf65b87c
commit 9bf9256049
2 changed files with 12 additions and 0 deletions

View file

@ -32,6 +32,7 @@ from frappe.utils import (
random_string,
scrub_urls,
validate_email_address,
validate_name,
validate_phone_number_with_country_code,
validate_url,
)
@ -342,6 +343,15 @@ class TestValidationUtils(unittest.TestCase):
"field",
)
def test_validate_name(self):
valid_names = ["", "abc", "asd a13", "asd-asd"]
for name in valid_names:
validate_name(name, True)
invalid_names = ["asd$wat", "asasd/ads"]
for name in invalid_names:
self.assertRaises(frappe.InvalidNameError, validate_name, name, True)
class TestImage(unittest.TestCase):
def test_strip_exif_data(self):

View file

@ -138,6 +138,8 @@ def validate_name(name, throw=False):
"""Returns True if the name is valid
valid names may have unicode and ascii characters, dash, quotes, numbers
anything else is considered invalid
Note: "Name" here is name of a person, not the primary key in Frappe doctypes.
"""
if not name:
return False