Files
OpenBB/tests/openbb_terminal/economy/test_fred_model.py
jose-donato 40cfe8148d Interactive tables using react (#4386)
* feat: experimenting tables with react

* feat: adding new interactive tables

* feat: adding more table features

* small changes

* update

* Update backend.py

* Update backend.py

* fix: dark mode?

* feat: lot of table improvements

* fix: my b

* fix: load only when prod

* feat: naive detect links and dates

* handle index and column names

* increased min width

* codespell

* mypy, pylint

* fix: added new chart, export, etc

* testing

* updates

* fix : add PLOT_OPEN_EXPORT,  USE_INTERACTIVE_DF to user dataclass

* bump pywry version, readd removed `plots_backend().start()`

* req files

* Update unit-test.yml

* Update unit-test.yml

* Update unit-test.yml

* updates

* fixing some date things

* update table

* fix formatting with timezones

* fixing some long prints and tables

* Mickey Mouse

Co-authored-by: teh_coderer <tehcoderer@users.noreply.github.com>
Co-authored-by: jose-donato <jose-donato@users.noreply.github.com>

* fix: ?!?!?

* adding limit arg to all print_rich_table

* tests

* lint

* simple by Default on interactive charts

* playing with some css (thks jose)

* Fix #4426

* Edit some structure

* fix sdk generation

* Update backend.py

* fa menu tested and working

* fix #4460

* fix #4460 drop indices

* update tests

* update tests

* Update helper_funcs.py

* tests

* Update unit-test.yml

* Update etf.ipynb

---------

Co-authored-by: teh_coderer <me@tehcoderer.com>
Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
Co-authored-by: teh_coderer <tehcoderer@users.noreply.github.com>
Co-authored-by: jose-donato <jose-donato@users.noreply.github.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
2023-03-13 17:50:48 +00:00

121 lines
3.0 KiB
Python

# IMPORTATION STANDARD
# IMPORTATION THIRDPARTY
import pandas as pd
import pytest
# IMPORTATION INTERNAL
from openbb_terminal.economy import fred_model
@pytest.fixture(scope="module")
def vcr_config():
return {
"filter_headers": [("User-Agent", None)],
"filter_query_parameters": [
("api_key", "MOCK_API_KEY"),
],
}
@pytest.mark.vcr
@pytest.mark.parametrize(
"func, kwargs_dict",
[("check_series_id", {"series_id": "DGS5"})],
)
def test_output(func, kwargs_dict, recorder):
payload = getattr(fred_model, func)(**kwargs_dict)
assert len(payload) > 0
assert "seriess" in payload
recorder.capture(payload["seriess"])
@pytest.mark.vcr
@pytest.mark.parametrize(
"func, kwargs_dict",
[
("get_series_notes", {"search_query": "finance"}),
("get_series_data", {"series_id": "DGS10", "start_date": "2020-01-01"}),
],
)
def test_check_output(func, kwargs_dict, recorder):
result_df = getattr(fred_model, func)(**kwargs_dict)
assert not result_df.empty
recorder.capture(result_df)
@pytest.mark.vcr
@pytest.mark.parametrize(
"func, kwargs_dict",
[
("check_series_id", {"series_id": "DGS5"}),
],
)
def test_invalid_response_status(func, kwargs_dict, mocker):
# MOCK GET
attrs = {
"status_code": 400,
"json.return_value": {"error_message": "mock error message"},
}
mock_response = mocker.Mock(**attrs)
mocker.patch(
target="openbb_terminal.helper_funcs.requests.get",
new=mocker.Mock(return_value=mock_response),
)
payload = getattr(fred_model, func)(**kwargs_dict)
assert len(payload) == 0
@pytest.mark.vcr
@pytest.mark.parametrize(
"func, kwargs_dict",
[("get_series_data", {"series_id": "DGS10", "start_date": "2020-01-01"})],
)
def test_load_data(func, kwargs_dict, recorder):
result_df = getattr(fred_model, func)(**kwargs_dict)
assert not result_df.empty
recorder.capture(result_df)
@pytest.mark.vcr
@pytest.mark.parametrize(
"func, kwargs_dict",
[
("get_cpi", {"countries": ["united kingdom"]}),
("get_cpi", {"countries": ["united kingdom", "united_states"]}),
("get_cpi", {"countries": ["united kingdom", "united_states", "belgium"]}),
(
"get_cpi",
{"countries": ["united kingdom", "united_states"], "frequency": "monthly"},
),
(
"get_cpi",
{
"countries": ["united kingdom", "united_states"],
"units": "growth_previous",
},
),
(
"get_cpi",
{"countries": ["united kingdom", "united_states"], "harmonized": True},
),
(
"get_cpi",
{
"countries": ["united kingdom", "united_states"],
"units": "growth_previous",
},
),
],
)
def test_get_cpi(func, kwargs_dict, recorder):
result_df = getattr(fred_model, func)(**kwargs_dict)
assert isinstance(result_df, pd.DataFrame)
recorder.capture(result_df)