diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 237f910..45d762a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -69,4 +69,5 @@ jobs: xil/onezero.py \ xil/discount.py \ xil/mercantile.py \ + xil/leumi.py \ # xil/poalim.py \ diff --git a/README.md b/README.md index b8d57d7..ad8067c 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The XIL project supports the following banks: | Bank and data source | XIL module | Tests | Bank name (Hebrew) | |------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|--------------------|------------------------------| -| [Bank Leumi Le-Israel](https://www.leumi.co.il/Lobby/currency_rates/40806/) | `leumi` | :x: | בנק לאומי לישראל | +| [Bank Leumi Le-Israel](https://www.leumi.co.il/Lobby/currency_rates/40806/) | `leumi` | :white_check_mark: | בנק לאומי לישראל | | [Bank Hapoalim](https://www.bankhapoalim.co.il/he/foreign-currency/exchange-rates) | `poalim` | :white_check_mark: | בנק הפועלים | | [Mizrahi Tefahot Bank](https://www.mizrahi-tefahot.co.il/brokerage/currancyexchange/) | `mizrahi_tefahot` | :x: | בנק מזרחי טפחות | | [Israel Discount Bank](https://www.discountbank.co.il/private/general-information/foreign-currency-transfers/exchange-rates/) | `discount` | :white_check_mark: | בנק דיסקונט לישראל | diff --git a/tests/_test_df.py b/tests/_test_df.py new file mode 100644 index 0000000..275bece --- /dev/null +++ b/tests/_test_df.py @@ -0,0 +1,13 @@ +# pylint: disable=missing-module-docstring +import pandas as pd + +from xil._currencies import CurrencyCode + + +def _test_df_sanity(df: pd.DataFrame, expected_currencies: list[CurrencyCode]) -> None: + """Test the actual vs. expected currencies and rates""" + assert (df.index == expected_currencies).all(), "The currencies are not as expected" + assert (df[("transfer", "sell")] > df[("transfer", "buy")]).all() + assert (df[("cash", "sell")] > df[("cash", "buy")]).all() + assert (df[("cash", "sell")] > df[("transfer", "sell")]).all() + assert (df[("transfer", "buy")] > df[("cash", "buy")]).all() diff --git a/tests/test_discount.py b/tests/test_discount.py index a92000e..8090398 100644 --- a/tests/test_discount.py +++ b/tests/test_discount.py @@ -65,7 +65,7 @@ def currencies_fixture() -> set[CurrencyCode]: @pytest.mark.live def test_df( - df: pd.DataFrame, currencies: set[CurrencyCode], drop_ngn: bool = True + df: pd.DataFrame, currencies: set[CurrencyCode], drop_ngn: bool = False ) -> None: assert set(df.index) == currencies if drop_ngn: diff --git a/tests/test_leumi.py b/tests/test_leumi.py new file mode 100644 index 0000000..512d6dd --- /dev/null +++ b/tests/test_leumi.py @@ -0,0 +1,36 @@ +# pylint: disable=missing-module-docstring, missing-function-docstring, redefined-outer-name +import pandas as pd +import pytest + +from xil._currencies import CurrencyCode +from xil.leumi import get_leumi_df + +from ._test_df import _test_df_sanity + + +@pytest.fixture +def df() -> pd.DataFrame: + return get_leumi_df() + + +@pytest.fixture() +def expected_currencies() -> list[CurrencyCode]: + return [ + CurrencyCode.USD, + CurrencyCode.EUR, + CurrencyCode.GBP, + CurrencyCode.JPY, + CurrencyCode.CHF, + CurrencyCode.AUD, + CurrencyCode.CAD, + CurrencyCode.ZAR, + CurrencyCode.AED, + CurrencyCode.SEK, + CurrencyCode.NOK, + CurrencyCode.DKK, + ] + + +@pytest.mark.live +def test_df(df: pd.DataFrame, expected_currencies: list[CurrencyCode]) -> None: + _test_df_sanity(df, expected_currencies) diff --git a/tests/test_poalim.py b/tests/test_poalim.py index 95d3a8c..598428a 100644 --- a/tests/test_poalim.py +++ b/tests/test_poalim.py @@ -9,6 +9,8 @@ from xil._currencies import CurrencyCode from xil.poalim import _get_url, get_df +from ._test_df import _test_df_sanity + skip_in_github_actions = pytest.mark.skipif( condition=os.getenv("CI") == "true", reason="Poalim API is requires human verification outside Israel", @@ -82,11 +84,7 @@ def expected_currencies() -> list[CurrencyCode]: @pytest.mark.live @skip_in_github_actions def test_df(df: pd.DataFrame, expected_currencies: list[CurrencyCode]) -> None: - assert (df.index == expected_currencies).all(), "The currencies are not as expected" - assert (df[("transfer", "sell")] > df[("transfer", "buy")]).all() - assert (df[("cash", "sell")] > df[("cash", "buy")]).all() - assert (df[("cash", "sell")] > df[("transfer", "sell")]).all() - assert (df[("transfer", "buy")] > df[("cash", "buy")]).all() + _test_df_sanity(df, expected_currencies) @pytest.mark.live diff --git a/xil/leumi.py b/xil/leumi.py index 2a72842..80a835c 100644 --- a/xil/leumi.py +++ b/xil/leumi.py @@ -52,7 +52,6 @@ def get_leumi_df(url: str = _LEUMI_URL) -> pd.DataFrame: """Get Leumi Bank exchange rates""" series = pd.read_json(url, typ="series", storage_options=UA_HEADER) # date = s.yatzigDate # Hour in `s.topHeaderText` - # pylint: disable-next=redefined-outer-name df = pd.json_normalize(series.data) df = df[ [ @@ -69,8 +68,3 @@ def get_leumi_df(url: str = _LEUMI_URL) -> pd.DataFrame: df = df.loc[df[("currency", "name")] != "סל המטבעות", :] df = LeumiNormalizer(df).norm() return df - - -if __name__ == "__main__": - df = get_leumi_df() - print(df)