Repository navigation
Expand file tree
/
Copy pathtest_es.py
More file actions
155 lines (138 loc) · 3.5 KB
/
Copy pathtest_es.py
File metadata and controls
155 lines (138 loc) · 3.5 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""Test i18n/es."""
from typing import Callable
# external
import pytest
# local
from validators import ValidationError, es_cif, es_doi, es_nie, es_nif
@pytest.mark.parametrize(
("value",),
[
("B25162520",),
("U4839822F",),
("B96817697",),
("P7067074J",),
("Q7899705C",),
("C75098681",),
("G76061860",),
("C71345375",),
("G20558169",),
("U5021960I",),
],
)
def test_returns_true_on_valid_cif(value: str):
"""Test returns true on valid cif."""
assert es_cif(value)
@pytest.mark.parametrize(
("value",),
[
("12345",),
("ABCDEFGHI",),
("Z5021960I",),
],
)
def test_returns_false_on_invalid_cif(value: str):
"""Test returns false on invalid cif."""
result = es_cif(value)
assert isinstance(result, ValidationError)
@pytest.mark.parametrize(
("value",),
[
("X0095892M",),
("X8868108K",),
("X2911154K",),
("Y2584969J",),
("X7536157T",),
("Y5840388N",),
("Z2915723H",),
("Y4002236C",),
("X7750702R",),
("Y0408759V",),
],
)
def test_returns_true_on_valid_nie(value: str):
"""Test returns true on valid nie."""
assert es_nie(value)
@pytest.mark.parametrize(
("value",),
[
("K0000023T",),
("L0000024R",),
("M0000025W",),
("00000026A",),
("00000027G",),
("00000028M",),
("00000029Y",),
("00000030F",),
("00000031P",),
("00000032D",),
("00000033X",),
("00000034B",),
("00000035N",),
("00000036J",),
("00000037Z",),
("00000038S",),
("00000039Q",),
("00000040V",),
("00000041H",),
("00000042L",),
("00000043C",),
("00000044K",),
("00000045E",),
],
)
def test_returns_true_on_valid_nif(value: str):
"""Test returns true on valid nif."""
assert es_nif(value)
def test_returns_false_on_invalid_nif():
"""Test returns false on invalid nif."""
result = es_nif("12345")
assert isinstance(result, ValidationError)
@pytest.mark.parametrize(
("value",),
[
# CIFs
("B25162520",),
("U4839822F",),
("B96817697",),
# NIEs
("X0000000T",),
("X0095892M",),
("X8868108K",),
("X2911154K",),
# NIFs
("00000001R",),
("00000000T",),
("26643189N",),
("07060225F",),
("49166693F",),
],
)
def test_returns_true_on_valid_doi(value: str):
"""Test returns true on valid doi."""
assert es_doi(value)
@pytest.mark.parametrize(
"digits",
[
"\uff10\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19",
"\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669",
"\u0966\u0967\u0968\u0969\u096a\u096b\u096c\u096d\u096e\u096f",
],
)
@pytest.mark.parametrize(
"validate,value",
[
(es_nif, "26643189N"),
(es_nie, "X0095892M"),
(es_cif, "B25162520"),
(es_doi, "26643189N"),
(es_doi, "X0095892M"),
(es_doi, "B25162520"),
],
)
def test_spanish_identifiers_reject_non_ascii_digits(
validate: Callable[[str], object], value: str, digits: str
):
"""Reject lookalike digit bodies even when their numeric checksums agree."""
translated = value[:-1].translate(str.maketrans("0123456789", digits)) + value[-1]
assert validate(value) is True
assert isinstance(validate(translated), ValidationError)