From d84ee8a66e36763be1dea16072ce95798bd1d2bd Mon Sep 17 00:00:00 2001 From: gabino Date: Mon, 23 Dec 2024 16:21:21 -0600 Subject: [PATCH] feat: add remove_bank function to manage bank entries --- clabe/__init__.py | 2 ++ clabe/validations.py | 15 +++++++++++++++ tests/test_clabe.py | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/clabe/__init__.py b/clabe/__init__.py index 23a453a..0905da0 100644 --- a/clabe/__init__.py +++ b/clabe/__init__.py @@ -8,6 +8,7 @@ 'get_bank_name', 'validate_clabe', 'configure_additional_bank', + 'remove_bank', ] from .banks import BANK_NAMES, BANKS @@ -17,6 +18,7 @@ configure_additional_bank, generate_new_clabes, get_bank_name, + remove_bank, validate_clabe, ) from .version import __version__ diff --git a/clabe/validations.py b/clabe/validations.py index ce5d228..9677567 100644 --- a/clabe/validations.py +++ b/clabe/validations.py @@ -98,3 +98,18 @@ def configure_additional_bank(bank_code_banxico: str, bank_name: str) -> None: ) BANKS[request.bank_code_abm] = request.bank_code_banxico BANK_NAMES[request.bank_code_banxico] = request.bank_name + + +def remove_bank(bank_code_banxico: str) -> None: + bank_code_abm = next( + ( + abm + for abm, banxico in BANKS.items() + if banxico == bank_code_banxico + ), + None, + ) + + if bank_code_abm: + BANKS.pop(bank_code_abm) + BANK_NAMES.pop(bank_code_banxico) diff --git a/tests/test_clabe.py b/tests/test_clabe.py index c0f0491..0e8cd22 100644 --- a/tests/test_clabe.py +++ b/tests/test_clabe.py @@ -5,6 +5,7 @@ configure_additional_bank, generate_new_clabes, get_bank_name, + remove_bank, validate_clabe, ) @@ -64,3 +65,9 @@ def test_configure_additional_bank_success(abm_code, banxico_code, name): def test_configure_additional_bank_invalid_inputs(banxico_code, name): with pytest.raises(ValueError): configure_additional_bank(banxico_code, name) + + +def test_remove_bank(): + remove_bank('40138') + with pytest.raises(ValueError): + get_bank_name('138')