File: test_email.py

package info (click to toggle)
validators 0.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 332 kB
  • sloc: python: 1,556; makefile: 150
file content (45 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download
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
# -*- coding: utf-8 -*-
import pytest

from validators import email, ValidationFailure


@pytest.mark.parametrize(('value', 'whitelist'), [
    ('email@here.com', None),
    ('weirder-email@here.and.there.com', None),
    ('email@[127.0.0.1]', None),
    ('example@valid-----hyphens.com', None),
    ('example@valid-with-hyphens.com', None),
    ('test@domain.with.idn.tld.उदाहरण.परीक्षा', None),
    ('email@localhost', None),
    ('email@localdomain', ['localdomain']),
    ('"test@test"@example.com', None),
    ('"\\\011"@here.com', None),
])
def test_returns_true_on_valid_email(value, whitelist):
    assert email(value, whitelist=whitelist)


@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',
    ),
    # Quoted-string format (CR not allowed)
    ('"\\\012"@here.com',),
])
def test_returns_failed_validation_on_invalid_email(value):
    assert isinstance(email(value), ValidationFailure)