Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for leumi #212

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions tests/_test_df.py
Original file line number Diff line number Diff line change
@@ -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()
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)
8 changes: 3 additions & 5 deletions tests/test_poalim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
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)