mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-03 16:02:04 +00:00
* refactor cboe for async * codespell * unused imports * pylint * more pylint * platform metadata * classmethod decorator * test params * intrinio quote * test param names * date in test needs to be a datetime.date not string * make fmp unix timestamp tz-aware and normalize percent change * different way of parsing datetime string * recapture cboe equity historical test * unused import * index snapshot update * black * extension map * pylint * cboe pyproject.toml * proposal to standardize equity_quote * one more file * removing changes on static assets * index_historical * index_historical again * last_time -> last_timestamp * obsolete router path * fix tests * test param * restore market index deprecation that I forgot about * fixing tests --------- Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
"""API integration tests for the derivatives extension."""
|
|
|
|
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=too-many-lines,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",
|
|
[
|
|
({"provider": "intrinio", "symbol": "AAPL", "date": "2023-01-25"}),
|
|
({"provider": "cboe", "symbol": "AAPL", "use_cache": False}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_derivatives_options_chains(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/derivatives/options/chains?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"symbol": "AAPL"}),
|
|
({"provider": "intrinio", "source": "delayed", "symbol": "AAPL"}),
|
|
({"provider": "intrinio", "symbol": "PLTR", "source": "delayed"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_derivatives_options_unusual(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/derivatives/options/unusual?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
(
|
|
{
|
|
"provider": "yfinance",
|
|
"interval": "1d",
|
|
"symbol": "CL,BZ",
|
|
"start_date": "2023-01-01",
|
|
"end_date": "2023-06-06",
|
|
"expiration": "2025-12",
|
|
}
|
|
),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_derivatives_futures_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/derivatives/futures/historical?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=10)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|
|
|
|
|
|
@parametrize(
|
|
"params",
|
|
[
|
|
({"provider": "cboe", "symbol": "VX", "date": None}),
|
|
({"provider": "yfinance", "symbol": "ES", "date": "2023-08-01"}),
|
|
],
|
|
)
|
|
@pytest.mark.integration
|
|
def test_derivatives_futures_curve(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/derivatives/futures/curve?{query_str}"
|
|
result = requests.get(url, headers=headers, timeout=30)
|
|
assert isinstance(result, requests.Response)
|
|
assert result.status_code == 200
|