Skip to content

Commit 7c97eca

Browse files
Fix: Allow Special DOI Cases Used in Public Administration Tests (#415)
* Remove special cases for valid codes The special cases excluded from the validation represent valid codes, used in test environments. * Update test_es.py * Update test_es.py * chore: formatting --------- Co-authored-by: Yozachar <[email protected]>
1 parent b2510d1 commit 7c97eca

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

src/validators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
fr_ssn,
2424
ind_aadhar,
2525
ind_pan,
26-
ru_inn
26+
ru_inn,
2727
)
2828
from .iban import iban
2929
from .ip_address import ipv4, ipv6

src/validators/i18n/es.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Spain."""
22

33
# standard
4-
from typing import Dict, Set
4+
from typing import Dict
55

66
# local
77
from validators.utils import validator
88

99

10-
def _nif_nie_validation(value: str, number_by_letter: Dict[str, str], special_cases: Set[str]):
10+
def _nif_nie_validation(value: str, number_by_letter: Dict[str, str]):
1111
"""Validate if the doi is a NIF or a NIE."""
12-
if value in special_cases or len(value) != 9:
12+
if len(value) != 9:
1313
return False
1414
value = value.upper()
1515
table = "TRWAGMYFPDXBNJZSQVHLCKE"
@@ -104,8 +104,7 @@ def es_nif(value: str, /):
104104
(ValidationError): If `value` is an invalid DOI string.
105105
"""
106106
number_by_letter = {"L": "0", "M": "0", "K": "0"}
107-
special_cases = {"X0000000T", "00000000T", "00000001R"}
108-
return _nif_nie_validation(value, number_by_letter, special_cases)
107+
return _nif_nie_validation(value, number_by_letter)
109108

110109

111110
@validator
@@ -137,7 +136,7 @@ def es_nie(value: str, /):
137136
number_by_letter = {"X": "0", "Y": "1", "Z": "2"}
138137
# NIE must must start with X Y or Z
139138
if value and value[0] in number_by_letter:
140-
return _nif_nie_validation(value, number_by_letter, {"X0000000T"})
139+
return _nif_nie_validation(value, number_by_letter)
141140
return False
142141

143142

src/validators/uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def uri(value: str, /):
6868

6969
# email
7070
if value.startswith("mailto:"):
71-
return email(value[len("mailto:"):])
71+
return email(value[len("mailto:") :])
7272

7373
# file
7474
if value.startswith("file:"):

tests/i18n/test_es.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,9 @@ def test_returns_true_on_valid_nif(value: str):
9494
assert es_nif(value)
9595

9696

97-
@pytest.mark.parametrize(
98-
("value",),
99-
[
100-
("12345",),
101-
("X0000000T",),
102-
("00000000T",),
103-
("00000001R",),
104-
],
105-
)
106-
def test_returns_false_on_invalid_nif(value: str):
97+
def test_returns_false_on_invalid_nif():
10798
"""Test returns false on invalid nif."""
108-
result = es_nif(value)
99+
result = es_nif("12345")
109100
assert isinstance(result, ValidationError)
110101

111102

@@ -117,10 +108,13 @@ def test_returns_false_on_invalid_nif(value: str):
117108
("U4839822F",),
118109
("B96817697",),
119110
# NIEs
111+
("X0000000T",),
120112
("X0095892M",),
121113
("X8868108K",),
122114
("X2911154K",),
123115
# NIFs
116+
("00000001R",),
117+
("00000000T",),
124118
("26643189N",),
125119
("07060225F",),
126120
("49166693F",),

0 commit comments

Comments
 (0)