Skip to content

Commit 6d164e1

Browse files
Doyoubelieveinfatenandgator
authored andcommitted
Require both check digits for individual INNs
1 parent 6ffd862 commit 6d164e1

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎src/validators/i18n/ru.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ def ru_inn(value: str):
5050
control_number1 = sum([d * w for d, w in zip(digits, weight_coefs1)]) % 11
5151
weight_coefs2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0]
5252
control_number2 = sum([d * w for d, w in zip(digits, weight_coefs2)]) % 11
53-
return (
54-
(control_number1 % 10) == digits[-2]
55-
if control_number1 > 9
56-
else control_number1 == digits[-2] and (control_number2 % 10) == digits[-1]
57-
if control_number2 > 9
58-
else control_number2 == digits[-1]
59-
)
53+
return (control_number1 % 10) == digits[-2] and (control_number2 % 10) == digits[-1]
6054
else:
6155
return False
6256
except ValueError:

‎tests/i18n/test_ru.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,22 @@ def test_returns_true_on_valid_ru_inn(value: str):
4646
def test_returns_false_on_valid_ru_inn(value: str):
4747
"""Test returns true on valid russian individual tax number."""
4848
assert isinstance(ru_inn(value), ValidationError)
49+
50+
51+
@pytest.mark.parametrize(
52+
"value",
53+
[
54+
"500100732266", # First check digit is wrong; the second matches.
55+
"100000001103", # First remainder is 10; the second check digit is wrong.
56+
"100000000781", # Second remainder is 10; its check digit must be zero.
57+
],
58+
)
59+
def test_individual_inn_requires_both_check_digits(value: str):
60+
"""Reject an individual INN when either check digit is wrong."""
61+
assert isinstance(ru_inn(value), ValidationError)
62+
63+
64+
@pytest.mark.parametrize("value", ["500100732259", "100000001102", "100000000780"])
65+
def test_individual_inn_check_digit_remainders(value: str):
66+
"""Accept both ordinary remainders and remainder 10 mapped to zero."""
67+
assert ru_inn(value) is True

0 commit comments

Comments
 (0)