Skip to content

Commit

Permalink
Passing tests (#5560)
Browse files Browse the repository at this point in the history
* Passing tests

* fix options

* Fix most tests and bugs

* fix forex missing params

* make symbol upper in polygon fx pairs

* fix fixedincome integration tests (#5564)

* Fixing charting api integration tests (#5562)

* fixing charting api integration tests

* black

* fix stocks less five API fails

* fix the 5 failing stocks integration tests

* recapture fmp stock news unit test

* fix fmp forex api test

* couple more forex integration fixes

* changing the request to always use the legacy session. @jmaslek this is was broken for 3.8 and 3.9; with this change apparently all versions work - lemme know if you see any issue with this change

* ruff

* fix ta

* add missing param

* fix testers for the api

* fix globalnews to use images instead of image

* remove unncessary pandas import

* econcal int tests

* update gitignore

* fix get_querystring to support lists

* add missing parameters

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
  • Loading branch information
3 people committed Oct 16, 2023
1 parent ab430a1 commit a5d2e83
Show file tree
Hide file tree
Showing 38 changed files with 488 additions and 369 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ cache/
# lightning logs
lightning_logs/

# user script to install all extensions and providers
openbb_platform/platform/core/tests/app/model/charts/test_chart_settings.py
# testing artifacts
*/mocked_path

# CA certificates
*.pem

# Platform auto generated files
openbb_platform/openbb/package/*
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ def test_chart_stocks_load(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]

chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand All @@ -82,8 +87,12 @@ def test_chart_stocks_multiples(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand All @@ -101,8 +110,12 @@ def test_chart_stocks_news(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -132,8 +145,12 @@ def test_chart_ta_adx(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand All @@ -152,8 +169,12 @@ def test_chart_ta_aroon(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -183,8 +204,12 @@ def test_chart_ta_ema(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -214,8 +239,12 @@ def test_chart_ta_hma(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -246,8 +275,12 @@ def test_chart_ta_macd(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -278,8 +311,12 @@ def test_chart_ta_rsi(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -309,8 +346,12 @@ def test_chart_ta_sma(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -340,8 +381,12 @@ def test_chart_ta_wma(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -371,5 +416,9 @@ def test_chart_ta_zlma(params, headers):
assert isinstance(result, requests.Response)
assert result.status_code == 200

assert result.json()["chart"]
assert list(result.json()["chart"].keys()) == ["content", "format"]
chart = result.json()["chart"]
fig = chart.pop("fig", {})

assert chart
assert not fig
assert list(chart.keys()) == ["content", "format"]
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,9 @@ def to_html(self, *args, **kwargs) -> str:

return super().to_html(*args, **kwargs)

def to_plotly_json(self, ndarray: bool = False) -> Dict[str, Any]:
def to_plotly_json(
self, ndarray: bool = False, np_nan: bool = False
) -> Dict[str, Any]:
"""
Convert figure to a JSON representation as a Python dict
Expand All @@ -1231,9 +1233,13 @@ def to_plotly_json(self, ndarray: bool = False) -> Dict[str, Any]:
----------
ndarray : `bool`, optional
If the plotly json should contain np.ndarray, by default False
np_nan : `bool`, optional
If the plotly json should contain np.nan, by default False
"""

def remove_ndarrays(data):
"""Remove ndarrays from the plotly json."""
if isinstance(data, dict):
for key, val in data.items():
if isinstance(val, np.ndarray):
Expand All @@ -1249,9 +1255,28 @@ def remove_ndarrays(data):

return data

def remove_nan(data):
"""Remove nan from the plotly json."""
if isinstance(data, dict):
for key, val in data.items():
if isinstance(val, float) and np.isnan(val):
data[key] = None
elif isinstance(val, (dict, list)):
data[key] = remove_nan(val)
elif isinstance(data, list):
for i, val in enumerate(data):
if isinstance(val, float) and np.isnan(val):
data[i] = None
elif isinstance(val, (dict, list)):
data[i] = remove_nan(val)

return data

plotly_json = super().to_plotly_json()
if not ndarray:
plotly_json = remove_ndarrays(plotly_json)
if not np_nan:
plotly_json = remove_nan(plotly_json)

return plotly_json

Expand Down
13 changes: 10 additions & 3 deletions openbb_platform/extensions/crypto/integration/test_crypto_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ def headers():
@pytest.mark.parametrize(
"params",
[
({"symbol": "BTCUSD", "start_date": "2023-01-01", "end_date": "2023-06-06"}),
(
{
"symbol": "BTC-USD",
"start_date": "2023-01-01",
"end_date": "2023-01-06",
"provider": "polygon",
}
),
(
{
"interval": "1min",
Expand All @@ -31,7 +38,7 @@ def headers():
),
(
{
"interval": "1day",
"interval": "15min",
"provider": "fmp",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
Expand Down Expand Up @@ -72,7 +79,7 @@ def headers():
"provider": "yfinance",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
"end_date": "2023-01-02",
"end_date": "2023-01-08",
}
),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@pytest.fixture(scope="session")
def obb(pytestconfig):
"""Fixture to setup obb."""

if pytestconfig.getoption("markexpr") != "not integration":
import openbb

Expand Down Expand Up @@ -36,11 +35,11 @@ def obb(pytestconfig):
),
(
{
"interval": "1day",
"interval": "15min",
"provider": "fmp",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"end_date": "2023-01-03",
"timeseries": 1,
}
),
Expand Down Expand Up @@ -70,16 +69,6 @@ def obb(pytestconfig):
"end_date": "2023-01-02",
}
),
(
{
"interval": "5m",
"period": "max",
"provider": "yfinance",
"symbol": "BTCUSD",
"start_date": "2023-01-01",
"end_date": "2023-01-02",
}
),
(
{
"interval": "1d",
Expand Down
Loading

0 comments on commit a5d2e83

Please sign in to comment.