mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
* add finviz provider * recapture tests * recapture tests again? * invalid test param * static packages * units_measurement -> unit_measurement * static packages as core only * openbb_core version bump in pyproject.toml * try adding user-agent to test response * fix tests * linting * provider model cosmetic changes * fix install script and typo in openbb toml * static * fix: re-record unittests * empty data error * definitions as a file --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: Pratyush Shukla <ps4534@nyu.edu> Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
266 lines
7.2 KiB
Python
266 lines
7.2 KiB
Python
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
|
|
|
|
|
|
@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')}"}
|
|
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"query": "", "provider": "fmp"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_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/etf/search?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
(
|
|
{
|
|
"symbol": "IOO",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-06-06",
|
|
"provider": "yfinance",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"symbol": "MISL",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-06-06",
|
|
"provider": "yfinance",
|
|
}
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_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/etf/historical?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"symbol": "IOO", "provider": "fmp"}),
|
|
({"symbol": "MISL", "provider": "fmp"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_info(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/etf/info?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"symbol": "IOO", "provider": "fmp"}),
|
|
({"symbol": "MISL", "provider": "fmp"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_sectors(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/etf/sectors?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"symbol": "QQQ", "cik": None, "provider": "fmp"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_holdings_date(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/etf/holdings_date?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
(
|
|
{
|
|
"symbol": "IOO",
|
|
"date": "2023-03-31",
|
|
"cik": None,
|
|
"provider": "fmp",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"symbol": "VOO",
|
|
"date": "2023-03-31",
|
|
"cik": None,
|
|
"provider": "fmp",
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"symbol": "TQQQ",
|
|
"date": None,
|
|
"provider": "sec",
|
|
"use_cache": False,
|
|
}
|
|
),
|
|
(
|
|
{
|
|
"symbol": "QQQ",
|
|
"date": "2021-06-30",
|
|
"provider": "sec",
|
|
"use_cache": False,
|
|
}
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_holdings(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/etf/holdings?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"symbol": "SPY,VOO,QQQ,IWM,IWN,GOVT,JNK", "provider": "fmp"}),
|
|
({"symbol": "SPY,VOO,QQQ,IWM,IWN,GOVT,JNK", "provider": "finviz"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_price_performance(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/etf/price_performance?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[({"symbol": "IOO"})],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_countries(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/etf/countries?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[({"sort": "desc", "limit": 10})],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_discovery_gainers(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/etf/discovery/gainers?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[({"sort": "desc", "limit": 10})],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_discovery_losers(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/etf/discovery/losers?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[({"sort": "desc", "limit": 10})],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_discovery_active(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/etf/discovery/active?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"symbol": "SPY", "provider": "fmp"}),
|
|
({"symbol": "QQQ", "provider": "fmp"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_etf_holdings_performance(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/etf/holdings_performance?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|