Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mypy-extensions>=1.0.0
mypy>=1.15.0,<2
packaging>=25.0
pytest>=6.0.1
python-stdnum>=1.20
setuptools>=80.9.0
tox>=4.24.1
twine>=6.2.0
Expand Down
13 changes: 13 additions & 0 deletions faker/providers/bank/no_NO/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
from .. import Provider as BankProvider

#: Weights applied to the first ten BBAN digits to derive the MOD11 check digit.
MOD11_WEIGHTS = (6, 7, 8, 9, 4, 5, 6, 7, 8, 9)


class Provider(BankProvider):
"""Implement bank provider for ``no_NO`` locale."""

bban_format = "###########"
country_code = "NO"

def bban(self) -> str:
"""Generate a valid BBAN with correct MOD11 check digit."""
while True:
first_10 = self.numerify("##########")
check = sum(w * int(d) for w, d in zip(MOD11_WEIGHTS, first_10)) % 11
# A remainder of 10 has no single-digit representation, so that
# draw is discarded and another one taken.
if check != 10:
return first_10 + str(check)
6 changes: 6 additions & 0 deletions tests/providers/test_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from stdnum import iban as iban_validator

from faker.providers.bank import Provider as BankProvider
from faker.providers.bank.az_AZ import Provider as AzAzBankProvider
from faker.providers.bank.cs_CZ import Provider as CsCZBankProvider
Expand Down Expand Up @@ -409,6 +411,10 @@ def test_iban(self, faker, num_samples):
assert iban[:2] == NoNoBankProvider.country_code
assert re.fullmatch(r"\d{2}\d{11}", iban[2:])

def test_iban_stdnum(self, faker, num_samples):
for _ in range(num_samples):
iban_validator.validate(faker.iban())


class TestPlPl:
"""Test pl_PL bank provider"""
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ deps =
coverage>=5.2
freezegun
pytest>=6.0.1
python-stdnum>=1.20
ukpostcodeparser>=1.1.1
validators>=0.13.0
sphinx>=2.4,<3.0
Expand Down