Skip to content

Commit 5336a2d

Browse files
kingbuzzmankvesteri
authored andcommitted
Adds better Locale() support, adds doi/nif/nie/doi validation to spain (python-validators#121)
1 parent 2e51683 commit 5336a2d

File tree

7 files changed

+365
-18
lines changed

7 files changed

+365
-18
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Changelog
22
---------
33

44

5+
0.13.0 (2019-??-??)
6+
^^^^^^^^^^^^^^^^^^
7+
8+
- Added new validator: ``es_doi``, ``es_nif``, ``es_cif``, ``es_nie``
9+
10+
511
0.12.6 (2019-05-08)
612
^^^^^^^^^^^^^^^^^^^
713

docs/index.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ You can install ``validators`` using pip::
3232
pip install validators
3333

3434

35-
Currently ``validators`` supports python versions 2.7, 3.3, 3.4, 3.5 and PyPy.
35+
Currently ``validators`` supports python versions 2.7, 3.3, 3.4, 3.5, 3.6, 3.7
36+
and PyPy.
3637

3738

3839
Basic validators
@@ -193,6 +194,32 @@ uuid
193194
i18n validators
194195
===============
195196

197+
Spanish
198+
-------
199+
200+
.. module:: validators.i18n.es
201+
202+
es_doi
203+
^^^^^^
204+
205+
.. autofunction:: es_doi
206+
207+
es_nif
208+
^^^^^^
209+
210+
.. autofunction:: es_nif
211+
212+
es_nie
213+
^^^^^^
214+
215+
.. autofunction:: es_nie
216+
217+
es_cif
218+
^^^^^^
219+
220+
.. autofunction:: es_cif
221+
222+
196223
Finnish
197224
-------
198225

tests/i18n/test_es.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
from validators import ValidationFailure
5+
from validators.i18n.es import es_cif, es_doi, es_nie, es_nif
6+
7+
8+
@pytest.mark.parametrize(('value',), [
9+
('B25162520',),
10+
('U4839822F',),
11+
('B96817697',),
12+
('P7067074J',),
13+
('Q7899705C',),
14+
('C75098681',),
15+
('G76061860',),
16+
('C71345375',),
17+
('G20558169',),
18+
('U5021960I',),
19+
])
20+
def test_returns_true_on_valid_cif(value):
21+
assert es_cif(value)
22+
23+
24+
@pytest.mark.parametrize(('value',), [
25+
('12345',),
26+
('ABCDEFGHI',),
27+
('Z5021960I',),
28+
])
29+
def test_returns_false_on_invalid_cif(value):
30+
result = es_cif(value)
31+
assert isinstance(result, ValidationFailure)
32+
33+
34+
@pytest.mark.parametrize(('value',), [
35+
('X0095892M',),
36+
('X8868108K',),
37+
('X2911154K',),
38+
('Y2584969J',),
39+
('X7536157T',),
40+
('Y5840388N',),
41+
('Z2915723H',),
42+
('Y4002236C',),
43+
('X7750702R',),
44+
('Y0408759V',),
45+
])
46+
def test_returns_true_on_valid_nie(value):
47+
assert es_nie(value)
48+
49+
50+
@pytest.mark.parametrize(('value',), [
51+
('K0000023T',),
52+
('L0000024R',),
53+
('M0000025W',),
54+
('00000026A',),
55+
('00000027G',),
56+
('00000028M',),
57+
('00000029Y',),
58+
('00000030F',),
59+
('00000031P',),
60+
('00000032D',),
61+
('00000033X',),
62+
('00000034B',),
63+
('00000035N',),
64+
('00000036J',),
65+
('00000037Z',),
66+
('00000038S',),
67+
('00000039Q',),
68+
('00000040V',),
69+
('00000041H',),
70+
('00000042L',),
71+
('00000043C',),
72+
('00000044K',),
73+
('00000045E',),
74+
])
75+
def test_returns_true_on_valid_nif(value):
76+
assert es_nif(value)
77+
78+
79+
@pytest.mark.parametrize(('value',), [
80+
('12345',),
81+
('X0000000T',),
82+
('00000000T',),
83+
('00000001R',),
84+
])
85+
def test_returns_false_on_invalid_nif(value):
86+
result = es_nif(value)
87+
assert isinstance(result, ValidationFailure)
88+
89+
90+
@pytest.mark.parametrize(('value',), [
91+
# CIFs
92+
('B25162520',),
93+
('U4839822F',),
94+
('B96817697',),
95+
# NIEs
96+
('X0095892M',),
97+
('X8868108K',),
98+
('X2911154K',),
99+
# NIFs
100+
('26643189N',),
101+
('07060225F',),
102+
('49166693F',),
103+
])
104+
def test_returns_true_on_valid_doi(value):
105+
assert es_doi(value)

tests/i18n/test_fi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22
import pytest
33

4-
from validators import fi_business_id, fi_ssn, ValidationFailure
4+
from validators import ValidationFailure
5+
from validators.i18n.fi import fi_business_id, fi_ssn
56

67

78
@pytest.mark.parametrize(('value',), [

validators/__init__.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
from .between import between # noqa
2-
from .domain import domain # noqa
3-
from .email import email # noqa
4-
from .extremes import Max, Min # noqa
5-
from .hashes import md5, sha1, sha224, sha256, sha512 # noqa
6-
from .i18n import fi_business_id, fi_ssn # noqa
7-
from .iban import iban # noqa
8-
from .ip_address import ipv4, ipv6 # noqa
9-
from .length import length # noqa
10-
from .mac_address import mac_address # noqa
11-
from .slug import slug # noqa
12-
from .truthy import truthy # noqa
13-
from .url import url # noqa
14-
from .utils import ValidationFailure, validator # noqa
15-
from .uuid import uuid # noqa
1+
from .between import between
2+
from .domain import domain
3+
from .email import email
4+
from .extremes import Max, Min
5+
from .hashes import md5, sha1, sha224, sha256, sha512
6+
from .i18n import fi_business_id, fi_ssn
7+
from .iban import iban
8+
from .ip_address import ipv4, ipv6
9+
from .length import length
10+
from .mac_address import mac_address
11+
from .slug import slug
12+
from .truthy import truthy
13+
from .url import url
14+
from .utils import ValidationFailure, validator
15+
from .uuid import uuid
1616

17-
__version__ = '0.12.6'
17+
__all__ = ('between', 'domain', 'email', 'Max', 'Min', 'md5', 'sha1', 'sha224',
18+
'sha256', 'sha512', 'fi_business_id', 'fi_ssn', 'iban', 'ipv4',
19+
'ipv6', 'length', 'mac_address', 'slug', 'truthy', 'url',
20+
'ValidationFailure', 'validator', 'uuid')
21+
22+
__version__ = '0.13.0'

validators/i18n/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
# TODO: remove, let the user import it if they really want it
12
from .fi import fi_business_id, fi_ssn # noqa
3+
4+
__all__ = ('fi_business_id', 'fi_ssn')

0 commit comments

Comments
 (0)