Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Corr account number (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhelyabuzhsky authored Nov 1, 2019
1 parent 4d3b83b commit 1446add
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
12 changes: 9 additions & 3 deletions django_ru_validators/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ def _check_bank_number(self, anumber: str) -> bool:
return (res % 10) == 0

def _check_bank_account_number(self, account: str, bik: Optional[str]) -> bool:
return (
if (
account is not None
and bik is not None
and len(account) == 20
and len(bik) == 9
and self._check_bank_number(bik[-3:] + account)
)
):
if bik[6] == "0" and bik[7] == "0":
# ключевание по правилам корреспондентского счёта
if self._check_bank_number("0" + bik[4:6] + account):
return True
if self._check_bank_number(bik[-3:] + account):
return True
return False

def __call__(self, value: str) -> None:
if not self._check_bank_account_number(value, self.bik):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="django_ru_validators",
version="1.6.3",
version="1.7.0",
description="Django RU validators",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
31 changes: 30 additions & 1 deletion tests/django_ru_validators/test_validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from django.core.exceptions import ValidationError

from django_ru_validators import validate_inn, BankAccountNumberValidator
from django_ru_validators import BankAccountNumberValidator, validate_inn


@pytest.mark.parametrize(
Expand Down Expand Up @@ -35,6 +35,9 @@ def test_validate_inn_wrong(inn):
("046577964", "40702810138030000017"),
("046577674", "40702810116480034147"),
("044525225", "40702810638050013199"),
("046577795", "47426810863032003088"),
("046577795", "40802810363030003088"),
("046577674", "40502810216020102982"),
],
)
def test_validate_bank_account_number_correct(bik, account_number):
Expand All @@ -51,10 +54,36 @@ def test_validate_bank_account_number_correct(bik, account_number):
("044525593", "4081781010867001741"),
("0445255931", "408178101086700174191"),
("044525593", "40817810108170017419"),
("046577795", "40502810216020102982"),
],
)
def test_validate_bank_account_number_wrong(bik, account_number):
with pytest.raises(ValidationError) as error_context:
validator = BankAccountNumberValidator(bik)
validator(account_number)
assert f"{account_number} является неверным номером счёта" in error_context.value


@pytest.mark.parametrize(
"bik,account_number",
[
("044525000", "40101810045250010041"),
("045004001", "40101810900000010001"),
("044030001", "40101810200000010001"),
("043510001", "40101810335100010001"),
],
)
def test_validate_bank_corr_account_number_correct(bik, account_number):
validator = BankAccountNumberValidator(bik)
validator(account_number)


@pytest.mark.parametrize(
"bik,account_number",
[("044525000", "40101810045250011041"), ("044030001", "40702810400000105745"),],
)
def test_validate_bank_corr_account_number_wrong(bik, account_number):
with pytest.raises(ValidationError) as error_context:
validator = BankAccountNumberValidator(bik)
validator(account_number)
assert f"{account_number} является неверным номером счёта" in error_context.value

0 comments on commit 1446add

Please sign in to comment.