Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions faker/providers/bank/no_NO/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ class Provider(BankProvider):

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

def bban(self) -> str:
"""Generate a valid BBAN with correct MOD11 check digit."""
for _ in range(100):
first_10 = self.numerify("##########")
weights = (6, 7, 8, 9, 4, 5, 6, 7, 8, 9)
check = sum(w * int(d) for w, d in zip(weights, first_10)) % 11
if check != 10:
return first_10 + str(check)
return first_10 + "0"
8 changes: 8 additions & 0 deletions tests/providers/test_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ 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):
try:
from stdnum import iban as iban_validator

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather add stdnum to the dev requirements and avoid the try ... except block

except ImportError:
pytest.skip("stdnum not available")
for _ in range(num_samples):
iban_validator.validate(faker.iban())


class TestPlPl:
"""Test pl_PL bank provider"""
Expand Down