From 2764b7d41a0e9efa80751315dae1b8f1f6d2c976 Mon Sep 17 00:00:00 2001 From: Theodore Aptekarev Date: Fri, 27 Oct 2023 09:29:56 +0200 Subject: [PATCH] Clean up the newly created ETF extension (#5611) * Add ETF to dev_install bundle * Add integration tests for openbb-etf * Patch integration test generator scripts to produce lintable code * Add py.typed markers for extensions --- openbb_platform/dev_install.py | 1 + .../charting/openbb_charting/py.typed | 0 .../extensions/crypto/openbb_crypto/py.typed | 0 .../econometrics/openbb_econometrics/py.typed | 0 .../economy/openbb_economy/py.typed | 0 .../etf/integration/test_etf_api.py | 51 +++++++++++++++++++ .../etf/integration/test_etf_python.py | 49 ++++++++++++++++++ .../extensions/etf/openbb_etf/py.typed | 0 .../fixedincome/openbb_fixedincome/py.typed | 0 .../extensions/forex/openbb_forex/py.typed | 0 .../futures/openbb_futures/py.typed | 0 .../extensions/news/openbb_news/py.typed | 0 .../extensions/qa/openbb_qa/py.typed | 0 .../extensions/stocks/openbb_stocks/py.typed | 0 .../extensions/ta/openbb_ta/py.typed | 0 .../utils/integration_tests_api_generator.py | 10 ++-- .../utils/integration_tests_generator.py | 18 ++++--- openbb_platform/openbb/py.typed | 0 .../platform/core/openbb_core/py.typed | 0 .../provider/openbb_provider/py.typed | 0 20 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 openbb_platform/extensions/charting/openbb_charting/py.typed create mode 100644 openbb_platform/extensions/crypto/openbb_crypto/py.typed create mode 100644 openbb_platform/extensions/econometrics/openbb_econometrics/py.typed create mode 100644 openbb_platform/extensions/economy/openbb_economy/py.typed create mode 100644 openbb_platform/extensions/etf/integration/test_etf_api.py create mode 100644 openbb_platform/extensions/etf/integration/test_etf_python.py create mode 100644 openbb_platform/extensions/etf/openbb_etf/py.typed create mode 100644 openbb_platform/extensions/fixedincome/openbb_fixedincome/py.typed create mode 100644 openbb_platform/extensions/forex/openbb_forex/py.typed create mode 100644 openbb_platform/extensions/futures/openbb_futures/py.typed create mode 100644 openbb_platform/extensions/news/openbb_news/py.typed create mode 100644 openbb_platform/extensions/qa/openbb_qa/py.typed create mode 100644 openbb_platform/extensions/stocks/openbb_stocks/py.typed create mode 100644 openbb_platform/extensions/ta/openbb_ta/py.typed create mode 100644 openbb_platform/openbb/py.typed create mode 100644 openbb_platform/platform/core/openbb_core/py.typed create mode 100644 openbb_platform/platform/provider/openbb_provider/py.typed diff --git a/openbb_platform/dev_install.py b/openbb_platform/dev_install.py index 55f3927e4e2..9a5d3da5970 100644 --- a/openbb_platform/dev_install.py +++ b/openbb_platform/dev_install.py @@ -27,6 +27,7 @@ openbb-crypto = { path = "./extensions/crypto", develop = true } openbb-economy = { path = "./extensions/economy", develop = true } +openbb-etf = { path = "./extensions/etf", develop = true } openbb-forex = { path = "./extensions/forex", develop = true } openbb-fixedincome = { path = "./extensions/fixedincome", develop = true } openbb-news = { path = "./extensions/news", develop = true } diff --git a/openbb_platform/extensions/charting/openbb_charting/py.typed b/openbb_platform/extensions/charting/openbb_charting/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/crypto/openbb_crypto/py.typed b/openbb_platform/extensions/crypto/openbb_crypto/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/econometrics/openbb_econometrics/py.typed b/openbb_platform/extensions/econometrics/openbb_econometrics/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/economy/openbb_economy/py.typed b/openbb_platform/extensions/economy/openbb_economy/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/etf/integration/test_etf_api.py b/openbb_platform/extensions/etf/integration/test_etf_api.py new file mode 100644 index 00000000000..e07edd1835c --- /dev/null +++ b/openbb_platform/extensions/etf/integration/test_etf_api.py @@ -0,0 +1,51 @@ +import base64 + +import pytest +import requests +from openbb_core.env import Env +from openbb_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 + + +@pytest.mark.parametrize( + "params", + [({})], +) +@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 + + +@pytest.mark.parametrize( + "params", + [ + ({"symbol": "IOO", "start_date": "2023-01-01", "end_date": "2023-06-06"}), + ({"symbol": "MISL", "start_date": "2023-01-01", "end_date": "2023-06-06"}), + ], +) +@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 diff --git a/openbb_platform/extensions/etf/integration/test_etf_python.py b/openbb_platform/extensions/etf/integration/test_etf_python.py new file mode 100644 index 00000000000..fdc8769696b --- /dev/null +++ b/openbb_platform/extensions/etf/integration/test_etf_python.py @@ -0,0 +1,49 @@ +"""Test etf extension.""" +import pytest +from openbb_core.app.model.obbject import OBBject + + +@pytest.fixture(scope="session") +def obb(pytestconfig): # pylint: disable=inconsistent-return-statements + """Fixture to setup obb.""" + + if pytestconfig.getoption("markexpr") != "not integration": + import openbb # pylint: disable=import-outside-toplevel + + return openbb.obb + + +# pylint: disable=redefined-outer-name + + +@pytest.mark.parametrize( + "params", + [ + ({}), + ], +) +@pytest.mark.integration +def test_etf_search(params, obb): + params = {p: v for p, v in params.items() if v} + + result = obb.etf.search(**params) + assert result + assert isinstance(result, OBBject) + assert len(result.results) > 0 + + +@pytest.mark.parametrize( + "params", + [ + ({"symbol": "IOO", "start_date": "2023-01-01", "end_date": "2023-06-06"}), + ({"symbol": "MISL", "start_date": "2023-01-01", "end_date": "2023-06-06"}), + ], +) +@pytest.mark.integration +def test_etf_historical(params, obb): + params = {p: v for p, v in params.items() if v} + + result = obb.etf.historical(**params) + assert result + assert isinstance(result, OBBject) + assert len(result.results) > 0 diff --git a/openbb_platform/extensions/etf/openbb_etf/py.typed b/openbb_platform/extensions/etf/openbb_etf/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/fixedincome/openbb_fixedincome/py.typed b/openbb_platform/extensions/fixedincome/openbb_fixedincome/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/forex/openbb_forex/py.typed b/openbb_platform/extensions/forex/openbb_forex/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/futures/openbb_futures/py.typed b/openbb_platform/extensions/futures/openbb_futures/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/news/openbb_news/py.typed b/openbb_platform/extensions/news/openbb_news/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/qa/openbb_qa/py.typed b/openbb_platform/extensions/qa/openbb_qa/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/stocks/openbb_stocks/py.typed b/openbb_platform/extensions/stocks/openbb_stocks/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/ta/openbb_ta/py.typed b/openbb_platform/extensions/ta/openbb_ta/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/extensions/tests/utils/integration_tests_api_generator.py b/openbb_platform/extensions/tests/utils/integration_tests_api_generator.py index 75b23dbd0f1..1a175e99287 100644 --- a/openbb_platform/extensions/tests/utils/integration_tests_api_generator.py +++ b/openbb_platform/extensions/tests/utils/integration_tests_api_generator.py @@ -28,12 +28,12 @@ def write_init_test_template(http_method: str, path: str): """Write some common initialization for the tests with the defined template.""" http_template_imports = {"get": "", "post": "import json"} template = http_template_imports[http_method] - template += """ + template += """import base64 + import pytest import requests -from openbb_provider.utils.helpers import get_querystring -import base64 from openbb_core.env import Env +from openbb_provider.utils.helpers import get_querystring @pytest.fixture(scope="session") @@ -43,6 +43,10 @@ def headers(): base64_bytes = base64.b64encode(userpass_bytes) return {"Authorization": f"Basic {base64_bytes.decode('ascii')}"} + + +# pylint: disable=redefined-outer-name + """ with open(path, "w") as f: diff --git a/openbb_platform/extensions/tests/utils/integration_tests_generator.py b/openbb_platform/extensions/tests/utils/integration_tests_generator.py index 38ce3381034..ba1b23125e2 100644 --- a/openbb_platform/extensions/tests/utils/integration_tests_generator.py +++ b/openbb_platform/extensions/tests/utils/integration_tests_generator.py @@ -52,6 +52,8 @@ def create_integration_test_files(extensions: List[PosixPath]) -> None: for extension in extensions: extension_name = extension.name test_file_name = f"test_{extension_name}_python.py" + if not (extension / "integration").exists(): + (extension / "integration").mkdir() test_file = extension / "integration" / test_file_name if not test_file.exists(): with open(test_file, "w", encoding="utf-8", newline="\n") as f: @@ -60,15 +62,19 @@ def create_integration_test_files(extensions: List[PosixPath]) -> None: import pytest from openbb_core.app.model.obbject import OBBject + @pytest.fixture(scope="session") -def obb(pytestconfig): +def obb(pytestconfig): # pylint: disable=inconsistent-return-statements """Fixture to setup obb.""" if pytestconfig.getoption("markexpr") != "not integration": - import openbb + import openbb # pylint: disable=import-outside-toplevel return openbb.obb - ''' + + +# pylint: disable=redefined-outer-name +''' ) @@ -163,9 +169,7 @@ def test_exists(command_name: str, path: str): def write_to_file_w_template(test_file, params_list, full_command, test_name, extra=""): """Write to file with template.""" - params = "" - for test_params in params_list: - params += f"({test_params}),\n" + params = ",\n".join(f"({test_params})" for test_params in params_list) if not test_exists(command_name=full_command, path=test_file): with open(test_file, "a", encoding="utf-8", newline="\n") as f: @@ -270,7 +274,7 @@ def write_commands_integration_tests() -> None: def write_charting_extension_integration_tests(): """Write charting extension integration tests.""" - import openbb_charting # pylint: disable=W0611 + import openbb_charting # pylint: disable=import-outside-toplevel functions = ChartingService.get_implemented_charting_functions() diff --git a/openbb_platform/openbb/py.typed b/openbb_platform/openbb/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/platform/core/openbb_core/py.typed b/openbb_platform/platform/core/openbb_core/py.typed new file mode 100644 index 00000000000..e69de29bb2d diff --git a/openbb_platform/platform/provider/openbb_provider/py.typed b/openbb_platform/platform/provider/openbb_provider/py.typed new file mode 100644 index 00000000000..e69de29bb2d