Files
OpenBB/openbb_platform/extensions/crypto/integration/test_crypto_api.py
Henrique Joaquim 4400cd9a8f Merge provider and core into core (#5774)
* small changes - moving provider inside the core

* uptade readme

* lint

* remove old provider readme

* leftovers

* refactor website examples

* ruff

* fix nox

* relock

* fix fails_to_deliver headers

* fix for tests that have renamed endpoints

* fix discovery

* removed test for renamed endpoint

* fix broken syntax - test_search_financial_attributes

* fix cash/income/balance

* fix derivatives tests

* fix etf tests

* fix news tests

* fix regulators

* black

* wrong test param

* sort equity gainers/losers by percent

* platform markdown generation import

* Hotfix/fix int tests core merge (#5779)

* removing tests on old endpoint

* removing visualization on old endpoint

* fixing equity tests

* fixing examples

* fix news tests

* fix index test

* example

* add comments

* example

---------

Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
2023-11-22 13:48:01 +00:00

147 lines
4.0 KiB
Python

"""Test crypto API endpoints."""
import base64
import pytest
import requests
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')}"}
@pytest.mark.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
@pytest.mark.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-06-06",
"timeseries": 1,
}
),
(
{
"multiplier": 1,
"timespan": "minute",
"sort": "desc",
"limit": 49999,
"adjusted": True,
"provider": "polygon",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
"end_date": "2023-01-02",
}
),
(
{
"multiplier": 1,
"timespan": "day",
"sort": "desc",
"limit": 49999,
"adjusted": True,
"provider": "polygon",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
(
{
"interval": "5m",
"period": "max",
"provider": "yfinance",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
"end_date": "2023-01-08",
}
),
(
{
"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-06-06",
}
),
],
)
@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