diff --git a/pyproject.toml b/pyproject.toml index 1771bc2..20110d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,15 +50,15 @@ Homepage = "https://github.com/OCHA-DAP/hdx-python-country" [project.optional-dependencies] test = ["pytest", "pytest-cov"] dev = ["pre-commit"] -wfp = ["data-bridges-client@git+https://github.com/WFP-VAM/DataBridgesAPI@dev#egg=data-bridges-client"] +#wfp = ["data-bridges-client@git+https://github.com/WFP-VAM/DataBridgesAPI@dev#egg=data-bridges-client"] ######### # Hatch # ######### -[tool.hatch.metadata] -allow-direct-references = true +#[tool.hatch.metadata] +#allow-direct-references = true # Build @@ -80,7 +80,7 @@ version_scheme = "python-simplified-semver" # Tests [tool.hatch.envs.test] -features = ["test", "wfp"] +features = ["test"]#, "wfp"] [tool.hatch.envs.test.scripts] test = """ diff --git a/requirements.txt b/requirements.txt index d9cd8d9..2b8b3c0 100755 --- a/requirements.txt +++ b/requirements.txt @@ -6,18 +6,13 @@ # annotated-types==0.6.0 # via pydantic -anyio==4.3.0 - # via httpx attrs==23.2.0 # via # frictionless # jsonlines # jsonschema certifi==2024.2.2 - # via - # httpcore - # httpx - # requests + # via requests cfgv==3.4.0 # via pre-commit chardet==5.2.0 @@ -29,11 +24,7 @@ click==8.1.7 colorama==0.4.6 # via typer coverage[toml]==7.4.3 - # via - # coverage - # pytest-cov -data-bridges-client @ git+https://github.com/WFP-VAM/DataBridgesAPI@dev - # via hdx-python-country (pyproject.toml) + # via pytest-cov distlib==0.3.8 # via virtualenv et-xmlfile==1.1.0 @@ -42,23 +33,14 @@ filelock==3.13.1 # via virtualenv frictionless==5.16.1 # via hdx-python-utilities -h11==0.14.0 - # via httpcore hdx-python-utilities==3.6.5 # via hdx-python-country (pyproject.toml) -httpcore==1.0.4 - # via httpx -httpx==0.27.0 - # via data-bridges-client humanize==4.9.0 # via frictionless identify==2.5.35 # via pre-commit idna==3.6 - # via - # anyio - # httpx - # requests + # via requests ijson==3.2.3 # via hdx-python-utilities iniconfig==2.0.0 @@ -106,9 +88,7 @@ ply==3.11 pre-commit==3.6.2 # via hdx-python-country (pyproject.toml) pydantic==2.6.3 - # via - # data-bridges-client - # frictionless + # via frictionless pydantic-core==2.16.3 # via pydantic pygments==2.17.2 @@ -125,7 +105,6 @@ pytest-cov==4.1.0 # via hdx-python-country (pyproject.toml) python-dateutil==2.8.2 # via - # data-bridges-client # frictionless # hdx-python-utilities # libhxl @@ -163,10 +142,6 @@ six==1.16.0 # via # isodate # python-dateutil -sniffio==1.3.1 - # via - # anyio - # httpx stringcase==1.2.0 # via frictionless structlog==24.1.0 @@ -178,12 +153,9 @@ tabulate==0.9.0 text-unidecode==1.3 # via python-slugify typer[all]==0.9.0 - # via - # frictionless - # typer + # via frictionless typing-extensions==4.10.0 # via - # data-bridges-client # frictionless # pydantic # pydantic-core @@ -192,9 +164,8 @@ unidecode==1.3.8 # via # libhxl # pyphonetics -urllib3==2.0.7 +urllib3==2.2.1 # via - # data-bridges-client # libhxl # requests validators==0.22.0 diff --git a/src/hdx/location/currency.py b/src/hdx/location/currency.py index 4c49439..20d3c58 100644 --- a/src/hdx/location/currency.py +++ b/src/hdx/location/currency.py @@ -29,7 +29,7 @@ class Currency: """ _primary_rates_url = "https://query2.finance.yahoo.com/v8/finance/chart/{currency}=X?period1={date}&period2={date}&interval=1d&events=div%2Csplit&formatted=false&lang=en-US®ion=US&corsDomain=finance.yahoo.com" - _secondary_rates_url = "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd.min.json" + _secondary_rates_url = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.min.json" _secondary_historic_url = ( "https://codeforiati.org/imf-exchangerates/imf_exchangerates.csv" ) diff --git a/src/hdx/location/wfp_exchangerates.py b/src/hdx/location/wfp_exchangerates.py index 1a8442b..952f539 100644 --- a/src/hdx/location/wfp_exchangerates.py +++ b/src/hdx/location/wfp_exchangerates.py @@ -1,18 +1,15 @@ from datetime import timezone from typing import Dict, List -from data_bridges_client.exceptions import ( - ApiException, -) - from . import get_int_timestamp from hdx.utilities.typehint import ListTuple try: from data_bridges_client import ApiClient, Configuration, CurrencyApi + from data_bridges_client.exceptions import ApiException from data_bridges_client.token import WfpApiToken except ImportError: - pass + WfpApiToken = None class WFPExchangeRates: diff --git a/tests/hdx/location/test_wfp_exchangerates.py b/tests/hdx/location/test_wfp_exchangerates.py index a5e41f0..7f18dd4 100644 --- a/tests/hdx/location/test_wfp_exchangerates.py +++ b/tests/hdx/location/test_wfp_exchangerates.py @@ -4,36 +4,39 @@ from hdx.location import get_int_timestamp from hdx.location.currency import Currency -from hdx.location.wfp_exchangerates import WFPExchangeRates +from hdx.location.wfp_exchangerates import WfpApiToken, WFPExchangeRates from hdx.utilities.dateparse import parse_date - -class TestWFPExchangeRates: - @pytest.fixture(scope="class") - def wfp_fx(self): - key = environ.get("WFP_KEY") - secret = environ.get("WFP_SECRET") - return WFPExchangeRates(key, secret) - - @pytest.fixture(scope="class") - def currency(self): - return "afn" - - @pytest.fixture(scope="class") - def date(self): - return parse_date("2020-02-20") - - def test_get_currencies(self, wfp_fx): - currencies = wfp_fx.get_currencies() - assert len(currencies) == 126 - - def test_get_historic_rates(self, wfp_fx, currency, date): - assert Currency.get_historic_rate(currency, date) == 76.80000305175781 - timestamp = get_int_timestamp(date) - historic_rates = wfp_fx.get_currency_historic_rates(currency) - assert historic_rates[timestamp] == 77.01 - - def test_get_all_historic_rates(self, wfp_fx, currency, date): - all_historic_rates = wfp_fx.get_historic_rates([currency]) - Currency.setup(historic_rates_cache=all_historic_rates) - assert Currency.get_historic_rate(currency, date) == 77.01 +if WfpApiToken is not None: + + class TestWFPExchangeRates: + @pytest.fixture(scope="class") + def wfp_fx(self): + key = environ.get("WFP_KEY") + secret = environ.get("WFP_SECRET") + return WFPExchangeRates(key, secret) + + @pytest.fixture(scope="class") + def currency(self): + return "afn" + + @pytest.fixture(scope="class") + def date(self): + return parse_date("2020-02-20") + + def test_get_currencies(self, wfp_fx): + currencies = wfp_fx.get_currencies() + assert len(currencies) == 126 + + def test_get_historic_rates(self, wfp_fx, currency, date): + assert ( + Currency.get_historic_rate(currency, date) == 76.80000305175781 + ) + timestamp = get_int_timestamp(date) + historic_rates = wfp_fx.get_currency_historic_rates(currency) + assert historic_rates[timestamp] == 77.01 + + def test_get_all_historic_rates(self, wfp_fx, currency, date): + all_historic_rates = wfp_fx.get_historic_rates([currency]) + Currency.setup(historic_rates_cache=all_historic_rates) + assert Currency.get_historic_rate(currency, date) == 77.01