-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathtest_email.py
More file actions
55 lines (49 loc) · 1.49 KB
/
test_email.py
File metadata and controls
55 lines (49 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Test eMail."""
# external
import pytest
# local
from validators import ValidationError, email
@pytest.mark.parametrize(
("value",),
[
("email@here.com",),
("weirder-email@here.and.there.com",),
("email@127.local.home.arpa",),
("example@valid-----hyphens.com",),
("example@valid-with-hyphens.com",),
("test@domain.with.idn.tld.उदाहरण.परीक्षा",),
("email@localhost.in",),
("Łókaść@email.com",),
("łemłail@here.com",),
("email@localdomain.org",),
('"\\\011"@here.com',),
],
)
def test_returns_true_on_valid_email(value: str):
"""Test returns true on valid email."""
assert email(value)
@pytest.mark.parametrize(
("value",),
[
(None,),
("",),
("abc",),
("abc@",),
("abc@bar",),
("a @x.cz",),
("abc@.com",),
("something@@somewhere.com",),
("email@127.0.0.1",),
("example@invalid-.com",),
("example@-invalid.com",),
("example@inv-.alid-.com",),
("example@inv-.-alid.com",),
("john56789.john56789.john56789.john56789.john56789.john56789.john5@example.com",),
('"test@test"@example.com',),
# Quoted-string format (CR not allowed)
('"\\\012"@here.com',),
],
)
def test_returns_failed_validation_on_invalid_email(value: str):
"""Test returns failed validation on invalid email."""
assert isinstance(email(value), ValidationError)