-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
91 lines (75 loc) · 2.37 KB
/
tests.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pytest
from validx import Dict
from validx.exc import ValidationError
from .classes import Email
valid_emails = [
'toto@gmail.com',
'toto.tata@gmail.com',
'toto_t@gmail.com',
'toto123@gmail.com',
]
company_valid_emails = list(
map(
lambda x: f"{x}@mycompany.com",
['denise.sabrina'
'marc.sanders',
'marketing_service',
'jean.dupont32'],
),
)
invalid_emails = [
'',
'toto@@gmail.com',
'.toto@gmail.com',
'toto..@gmail.com',
'..toto@gmail.com',
'toto..tata@gmail.com',
'.@gmail.com',
'@',
'@gmail.com',
'123@gm',
]
@pytest.mark.parametrize("email", valid_emails)
@pytest.mark.parametrize("minlen", [None, 1])
@pytest.mark.parametrize("maxlen", [None, max(map(len, valid_emails))])
def test_valid_email(email, minlen, maxlen):
schema = Email(minlen=minlen, maxlen=maxlen)
try:
schema(email)
except Exception as error:
pytest.fail(
f'{email}:{min}:{max} is not valid email as expected, {error}'
)
@pytest.mark.parametrize("email", invalid_emails)
@pytest.mark.parametrize("minlen", [None, 1 + max(map(len, valid_emails))])
@pytest.mark.parametrize("maxlen", [None])
def test_invalid_email(email, minlen, maxlen):
schema = Email(minlen=minlen, maxlen=maxlen)
with pytest.raises(ValidationError):
schema(email)
@pytest.mark.parametrize("email", company_valid_emails)
@pytest.mark.parametrize("pattern", [r".*@mycompany.com"])
def test_valid_email_with_valid_pattern(email, pattern):
schema = Email(pattern=pattern)
try:
schema(email)
except Exception as error:
pytest.fail(f'{email} is not valid email as expected, {error}')
@pytest.mark.parametrize("email", company_valid_emails)
@pytest.mark.parametrize("pattern", [r".*@myCOMpany.com", ])
def test_valid_email_with_invalid_pattern(email, pattern):
with pytest.raises(ValidationError):
schema = Email(pattern=pattern)
schema(email)
@pytest.mark.parametrize('email', company_valid_emails)
@pytest.mark.parametrize('pattern', [r".*@mycompany.com$"])
def test_validx_dict_with_valid_email(email, pattern):
schema = Dict({
'email': Email(pattern=pattern),
})
try:
schema({'email': email})
except Exception as error:
pytest.fail(
f'{email} is not valid email as expected, {error}',
)