File: test_registry.py

package info (click to toggle)
python-schwifty 2024.09.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,072 kB
  • sloc: python: 3,057; makefile: 209; sh: 9
file content (45 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from schwifty import BIC
from schwifty import registry
from schwifty.checksum.poland import DefaultAlgorithm


def test_validate_bics():
    for bic in (bank["bic"] for bank in registry.get("bank") if bank["bic"]):
        BIC(bic, allow_invalid=False)


def test_validate_cz_encoding():
    assert "Komerční banka, a.s.", "Československá obchodní banka, a. s." in [
        bank["name"] for bank in registry.get("bank") if bank["country_code"] == "CZ"
    ]


def test_valid_national_checksum_pl():
    bank_by_country = registry.get("country")
    algo = DefaultAlgorithm()
    for bank in bank_by_country["PL"]:
        bank_code = bank["bank_code"]
        check_digit = bank_code[7]
        branch_code = bank_code[3:7]
        bank_code = bank_code[:3]

        assert algo.compute([bank_code, branch_code]) == check_digit


def test_bank_code_matches_spec():
    bank_by_country = registry.get("country")
    specs = registry.get("iban")

    for country_code, banks in bank_by_country.items():
        spec = specs[country_code]
        start, end = spec["bban_length"], 0
        for component in spec.get("bic_lookup_components", ["bank_code"]):
            a, b = spec["positions"][component]
            start = min(start, a)
            end = max(end, b)
        length = end - start
        for bank in banks:
            bank_code = bank["bank_code"]
            if not bank_code:
                continue
            assert len(bank_code) == length