Skip to content

Commit 5b1b0a1

Browse files
authored
Return True from validate_national_checksum on success (#290)
BBAN.validate_national_checksum() returned False when the national checksum was valid, while the no-checksum-algorithm branch returned True for the same 'valid' meaning. As documented, the method raises on an invalid checksum, so the boolean return should be True when the checksum is valid. A valid IBAN such as BE68539007547034 therefore wrongly reported False.
1 parent 8a6811d commit 5b1b0a1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

schwifty/bban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def validate_national_checksum(self) -> bool:
251251
components = [self._get_component(component) for component in algo.accepts]
252252
if not algo.validate(components, self.national_checksum_digits):
253253
raise exceptions.InvalidBBANChecksum("Invalid national checksum")
254-
return False
254+
return True
255255

256256
def _get_component(self, component_type: Component) -> str:
257257
position = _get_position_range(self.spec, component_type)

tests/test_bban.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import pytest
22

33
from schwifty.bban import BBAN
4+
from schwifty.exceptions import InvalidBBANChecksum
5+
6+
7+
def test_validate_national_checksum() -> None:
8+
# A valid national checksum returns True (consistent with the "no checksum
9+
# algorithm" case), while an invalid one raises InvalidBBANChecksum.
10+
assert BBAN("BE", "539007547034").validate_national_checksum() is True
11+
assert BBAN("GB", "WEST12345698765432").validate_national_checksum() is True
12+
with pytest.raises(InvalidBBANChecksum):
13+
BBAN("BE", "539007547035").validate_national_checksum()
414

515

616
@pytest.mark.parametrize("country_code", ["DE", "ES", "GB", "FR", "PL"])

0 commit comments

Comments
 (0)