Skip to content

Commit

Permalink
fix: Read BIC from BBAN
Browse files Browse the repository at this point in the history
  • Loading branch information
mdomke committed Oct 14, 2024
1 parent 5c91df5 commit 7c127c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion schwifty/bban.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def from_components(cls, country_code: str, **values: str) -> BBAN:
InvalidAccountCode: If the account code does not meet the national requirements.
"""
spec: dict[str, Any] = _get_bban_spec(country_code)
if "positions" not in spec:
if "positions" not in spec: # pragma: no cover
raise exceptions.SchwiftyException(f"BBAN generation for {country_code} not supported")

ranges = _get_position_ranges(spec)
Expand Down
9 changes: 1 addition & 8 deletions schwifty/iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from schwifty import exceptions
from schwifty import registry
from schwifty.bban import BBAN
from schwifty.bban import Component
from schwifty.bic import BIC
from schwifty.checksum import ISO7064_mod97_10
from schwifty.checksum import numerify
Expand Down Expand Up @@ -294,13 +293,7 @@ def bic(self) -> BIC | None:
.. versionchanged:: 2020.08.1
Returns ``None`` if no appropriate :class:`BIC` can be constructed.
"""
key = ""
for attr in self.spec.get("bic_lookup_components", [Component.BANK_CODE]):
key += getattr(self, attr, "")
try:
return BIC.from_bank_code(self.country_code, key)
except exceptions.SchwiftyException:
return None
return self.bban.bic

@property
def country(self) -> Data | None:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_iban.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def test_iban_properties_de() -> None:
assert iban.bank_code == "43060967"
assert iban.branch_code == ""
assert iban.account_code == "7000534100"
assert iban.account_id == ""
assert iban.account_type == ""
assert iban.country_code == "DE"
assert iban.currency_code == ""
assert iban.account_holder_id == ""
assert iban.national_checksum_digits == ""
assert iban.bic == "GENODEM1GLS"
assert iban.formatted == "DE42 4306 0967 7000 5341 00"
Expand All @@ -233,6 +237,15 @@ def test_iban_properties_it() -> None:
assert iban.in_sepa_zone is True


def test_iban_properties_is() -> None:
iban = IBAN("IS14 0159 2600 7654 5510 7303 39")
assert iban.account_holder_id == "5510730339"
assert iban.account_code == "007654"
assert iban.account_type == "26"
assert iban.branch_code == "59"
assert iban.bank_code == "01"


@pytest.mark.parametrize(
("components", "compact"),
[
Expand Down

0 comments on commit 7c127c8

Please sign in to comment.