refactor: Avoid regex for email validation

[skip ci]
This commit is contained in:
Ankush Menat 2023-09-02 11:35:33 +05:30
parent 98fce7d633
commit 1ad5c0ea86
2 changed files with 7 additions and 2 deletions

View file

@ -102,11 +102,13 @@ class TestBoilerPlate(unittest.TestCase):
invalid_inputs = copy.copy(self.default_user_input).update(
{
"title": ["1nvalid Title", "valid title"],
"email": ["notavalidemail", "what@is@this.email", "example@example.org"],
}
)
with patch("sys.stdin", self.get_user_input_stream(invalid_inputs)):
hooks = _get_user_inputs(self.default_hooks.app_name)
self.assertEqual(hooks.app_title, "valid title")
self.assertEqual(hooks.app_email, "example@example.org")
def test_valid_ci_yaml(self):
yaml.safe_load(github_workflow_template.format(**self.default_hooks))

View file

@ -16,7 +16,6 @@ import frappe
from frappe.utils import touch_file
APP_TITLE_PATTERN = re.compile(r"^(?![\W])[^\d_\s][\w -]+$", flags=re.UNICODE)
EMAIL_PATTERN = re.compile(r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", flags=re.UNICODE)
def make_boilerplate(dest, app_name, no_git=False):
@ -74,7 +73,11 @@ def _get_user_inputs(app_name):
def is_valid_email(email) -> bool:
if not EMAIL_PATTERN.match(email):
from email.headerregistry import Address
try:
Address(addr_spec=email)
except Exception:
print("App Email should be a valid email address.")
return False
return True