Skip to content

Commit

Permalink
Cover leumi module with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jond01 committed Jul 20, 2024
1 parent 6299e88 commit 3397b38
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ jobs:
xil/onezero.py \
xil/discount.py \
xil/mercantile.py \
xil/leumi.py \
# xil/poalim.py \
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: | בנק דיסקונט לישראל |
Expand Down
2 changes: 1 addition & 1 deletion tests/test_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions tests/test_leumi.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 0 additions & 6 deletions xil/leumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
[
Expand All @@ -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)

0 comments on commit 3397b38

Please sign in to comment.