Skip to content

Commit

Permalink
Revert "Allow passing of test_environment flag to email_validator."
Browse files Browse the repository at this point in the history
This reverts commit 68cf9b0.
  • Loading branch information
azmeuk committed Jul 17, 2022
1 parent 582ced8 commit aa4e043
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 40 deletions.
1 change: 0 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Version 3.0.2
Unreleased

- Delayed import of ``email_validator``. :issue:`727`
- Pass ``test_environment`` flag to ``email_validator``.

Version 3.0.1
-------------
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ install_requires = MarkupSafe
where = src

[options.extras_require]
email = email_validator >= 1.2.0
email = email_validator

[extract_messages]
copyright_holder = WTForms Team
Expand Down
9 changes: 0 additions & 9 deletions src/wtforms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,6 @@ class Email:
:param allow_empty_local:
Allow an empty local part (i.e. @example.com), e.g. for validating
Postfix aliases (Default False).
:param test_environment:
DNS-based deliverability checks are disabled and the Special Use Domain
Name ``test`` is permitted.
.. versionadded:: 3.0.2
The *test_environment* parameter.
"""

def __init__(
Expand All @@ -389,14 +383,12 @@ def __init__(
check_deliverability=False,
allow_smtputf8=True,
allow_empty_local=False,
test_environment=False,
):
self.message = message
self.granular_message = granular_message
self.check_deliverability = check_deliverability
self.allow_smtputf8 = allow_smtputf8
self.allow_empty_local = allow_empty_local
self.test_environment = test_environment

def __call__(self, form, field):
try:
Expand All @@ -414,7 +406,6 @@ def __call__(self, form, field):
check_deliverability=self.check_deliverability,
allow_smtputf8=self.allow_smtputf8,
allow_empty_local=self.allow_empty_local,
test_environment=self.test_environment,
)
except email_validator.EmailNotValidError as e:
message = self.message
Expand Down
32 changes: 3 additions & 29 deletions tests/validators/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_valid_email_passes(email_address, dummy_form, dummy_field):
"foo.@bar.co",
"foo@foo@bar.co",
"fo o@bar.co",
"foo@bar.test",
],
)
def test_invalid_email_raises(email_address, dummy_form, dummy_field):
Expand All @@ -48,33 +47,8 @@ def test_invalid_email_raises(email_address, dummy_form, dummy_field):
assert str(e.value) == "Invalid email address."


@pytest.mark.parametrize("email_address", ["foo@bar.test"])
def test_invalid_email_passes_in_test_environment(
email_address, dummy_form, dummy_field
):
"""
When test_environment=True email addresses with test domain should pass
without raising
"""
validator = email(test_environment=True)
dummy_field.data = email_address
validator(dummy_form, dummy_field)


@pytest.mark.parametrize(
"email_address,message",
[
("foo@", "There must be something after the @-sign."),
(
"foo@bar.test",
"The domain name bar.test is a special-use or reserved name"
" that cannot be used with email.",
),
],
)
def test_invalid_email_raises_granular_message(
email_address, message, dummy_form, dummy_field
):
@pytest.mark.parametrize("email_address", ["foo@"])
def test_invalid_email_raises_granular_message(email_address, dummy_form, dummy_field):
"""
When granular_message=True uses message from email_validator library.
"""
Expand All @@ -83,4 +57,4 @@ def test_invalid_email_raises_granular_message(
with pytest.raises(ValidationError) as e:
validator(dummy_form, dummy_field)

assert str(e.value) == message
assert str(e.value) == "There must be something after the @-sign."

0 comments on commit aa4e043

Please sign in to comment.