|
| 1 | +"""Test eMail.""" |
1 | 2 | # -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +# standard |
2 | 5 | import pytest |
3 | 6 |
|
| 7 | +# local |
4 | 8 | from validators import email, ValidationFailure |
5 | 9 |
|
6 | 10 |
|
7 | | -@pytest.mark.parametrize(('value', 'whitelist'), [ |
8 | | - ('email@here.com', None), |
9 | | - ('weirder-email@here.and.there.com', None), |
10 | | - ('email@[127.0.0.1]', None), |
11 | | - ('example@valid-----hyphens.com', None), |
12 | | - ('example@valid-with-hyphens.com', None), |
13 | | - ('test@domain.with.idn.tld.उदाहरण.परीक्षा', None), |
14 | | - ('email@localhost', None), |
15 | | - ('email@localdomain', ['localdomain']), |
16 | | - ('"test@test"@example.com', None), |
17 | | - ('"\\\011"@here.com', None), |
18 | | -]) |
19 | | -def test_returns_true_on_valid_email(value, whitelist): |
20 | | - assert email(value, whitelist=whitelist) |
| 11 | +@pytest.mark.parametrize( |
| 12 | + ("value",), |
| 13 | + [ |
| 14 | + ("email@here.com",), |
| 15 | + ("weirder-email@here.and.there.com",), |
| 16 | + ("email@127.local.home.arpa",), |
| 17 | + ("example@valid-----hyphens.com",), |
| 18 | + ("example@valid-with-hyphens.com",), |
| 19 | + ("test@domain.with.idn.tld.उदाहरण.परीक्षा",), |
| 20 | + ("email@localhost.in",), |
| 21 | + ("email@localdomain.org",), |
| 22 | + ('"\\\011"@here.com',), |
| 23 | + ], |
| 24 | +) |
| 25 | +def test_returns_true_on_valid_email(value: str): |
| 26 | + """Test returns true on valid email.""" |
| 27 | + assert email(value) |
21 | 28 |
|
22 | 29 |
|
23 | | -@pytest.mark.parametrize(('value',), [ |
24 | | - (None,), |
25 | | - ('',), |
26 | | - ('abc',), |
27 | | - ('abc@',), |
28 | | - ('abc@bar',), |
29 | | - ('a @x.cz',), |
30 | | - ('abc@.com',), |
31 | | - ('something@@somewhere.com',), |
32 | | - ('email@127.0.0.1',), |
33 | | - ('example@invalid-.com',), |
34 | | - ('example@-invalid.com',), |
35 | | - ('example@inv-.alid-.com',), |
36 | | - ('example@inv-.-alid.com',), |
37 | | - ( |
38 | | - 'john56789.john56789.john56789.john56789.john56789.john56789.john5' |
39 | | - '@example.com', |
40 | | - ), |
41 | | - # Quoted-string format (CR not allowed) |
42 | | - ('"\\\012"@here.com',), |
43 | | -]) |
44 | | -def test_returns_failed_validation_on_invalid_email(value): |
| 30 | +@pytest.mark.parametrize( |
| 31 | + ("value",), |
| 32 | + [ |
| 33 | + (None,), |
| 34 | + ("",), |
| 35 | + ("abc",), |
| 36 | + ("abc@",), |
| 37 | + ("abc@bar",), |
| 38 | + ("a @x.cz",), |
| 39 | + ("abc@.com",), |
| 40 | + ("something@@somewhere.com",), |
| 41 | + ("email@127.0.0.1",), |
| 42 | + ("example@invalid-.com",), |
| 43 | + ("example@-invalid.com",), |
| 44 | + ("example@inv-.alid-.com",), |
| 45 | + ("example@inv-.-alid.com",), |
| 46 | + ("john56789.john56789.john56789.john56789.john56789.john56789.john5@example.com",), |
| 47 | + ('"test@test"@example.com',), |
| 48 | + # Quoted-string format (CR not allowed) |
| 49 | + ('"\\\012"@here.com',), |
| 50 | + ], |
| 51 | +) |
| 52 | +def test_returns_failed_validation_on_invalid_email(value: str): |
| 53 | + """Test returns failed validation on invalid email.""" |
45 | 54 | assert isinstance(email(value), ValidationFailure) |
0 commit comments