mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
* fix: remove specific imports * make polygon historical tz-aware * undo including that commit * that PR wasn't supposed to be there. * pylint unused argument * fix polygon crypto historical intervals * pylint * new cassette * fix the rest of the polygon historical price query params * black * pylint.. * integration test param * appease daylight savings handling * paginate for crypto currency and index * black * raise EmptyDataError when no results instead of returning an empty list * ruff --------- Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
135 lines
3.6 KiB
Python
135 lines
3.6 KiB
Python
"""Test crypto API endpoints."""
|
|
|
|
import base64
|
|
|
|
import pytest
|
|
import requests
|
|
from extensions.tests.conftest import parametrize
|
|
from openbb_core.env import Env
|
|
from openbb_core.provider.utils.helpers import get_querystring
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def headers():
|
|
userpass = f"{Env().API_USERNAME}:{Env().API_PASSWORD}"
|
|
userpass_bytes = userpass.encode("ascii")
|
|
base64_bytes = base64.b64encode(userpass_bytes)
|
|
|
|
return {"Authorization": f"Basic {base64_bytes.decode('ascii')}"}
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"query": "asd"}),
|
|
({"query": "btc", "provider": "fmp"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_crypto_search(params, headers):
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://0.0.0.0:8000/api/v1/crypto/search?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
(
|
|
{
|
|
"symbol": "BTC-USD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-01-06",
|
|
"provider": "polygon",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"interval": "1min",
|
|
"provider": "fmp",
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-01-02",
|
|
"timeseries": 1,
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"interval": "15min",
|
|
"provider": "fmp",
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-01-03",
|
|
"timeseries": 1,
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"interval": "1m",
|
|
"sort": "desc",
|
|
"limit": 49999,
|
|
"provider": "polygon",
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-01-02",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"interval": "1d",
|
|
"sort": "desc",
|
|
"limit": 49999,
|
|
"provider": "polygon",
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-06-06",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"interval": "1d",
|
|
"period": "max",
|
|
"provider": "yfinance",
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-06-06",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"provider": "tiingo",
|
|
"interval": "1day",
|
|
"exchanges": ["POLONIEX", "GDAX"],
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-06-06",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"provider": "tiingo",
|
|
"interval": "1hour",
|
|
"exchanges": ["POLONIEX", "GDAX"],
|
|
"symbol": "BTCUSD",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-01-02",
|
|
}
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_crypto_price_historical(params, headers):
|
|
params = {p: v for p, v in params.items() if v}
|
|
|
|
query_str = get_querystring(params, [])
|
|
url = f"http://0.0.0.0:8000/api/v1/crypto/price/historical?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|