Skip to content

Commit

Permalink
fix: unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
montezdesousa committed May 21, 2024
1 parent 8282406 commit faf1180
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 59 deletions.
9 changes: 3 additions & 6 deletions openbb_platform/core/tests/app/model/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@

def test_defaults():
"""Test the Defaults class."""
cc = Defaults(routes={"test": {"test": "test"}})
cc = Defaults(commands={"/equity/price": {"provider": "test"}})
assert isinstance(cc, Defaults)
assert cc.routes == {"test": {"test": "test"}}
assert cc.commands == {"equity.price": {"provider": "test"}}


def test_fields():
"""Test the Defaults fields."""
fields = Defaults.model_fields
fields_keys = fields.keys()

assert "routes" in fields_keys
assert "commands" in Defaults.model_fields
55 changes: 4 additions & 51 deletions openbb_platform/core/tests/app/test_command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,52 +177,6 @@ def other_mock_func(
assert result["cc"].user_settings == user_settings


@pytest.mark.parametrize(
"command_coverage, route, kwargs, route_default, expected_result",
[
(
{"route1": ["choice1", "choice2"]},
"route1",
{"provider_choices": {"provider": None}},
None,
{"provider_choices": {"provider": None}},
),
(
{"route1": ["choice1", "choice2"]},
"route1",
{"provider_choices": {"provider": ["choice1", "choice2"]}},
{"provider": "choice1"},
{"provider_choices": {"provider": ["choice1", "choice2"]}},
),
(
{},
"route2",
{},
{"provider": "default_provider"},
{},
),
(
{},
"route3",
{"provider_choices": {"provider": "existing_provider"}},
None,
{"provider_choices": {"provider": "existing_provider"}},
),
],
)
def test_parameters_builder_update_provider_choices(
command_coverage, route, kwargs, route_default, expected_result
):
"""Test update_provider_choices."""
with patch("openbb_core.app.command_runner.ProviderInterface") as mock_pi:
mock_pi.available_providers = ["provider1", "provider2"]
result = ParametersBuilder.update_provider_choices(
mock_func, command_coverage, route, kwargs, route_default
)

assert result == expected_result


def test_parameters_builder_validate_kwargs(mock_func):
"""Test validate_kwargs."""
# TODO: add more test cases with @pytest.mark.parametrize
Expand Down Expand Up @@ -253,7 +207,7 @@ def test_parameters_builder__warn_kwargs(extra_params, base, expect):
"""Test _warn_kwargs."""

@dataclass
class SomeModel(base):
class SomeModel(base): # type: ignore[misc,valid-type]
"""SomeModel"""

exists: QueryParam = Query(...)
Expand All @@ -276,27 +230,26 @@ def test_parameters_builder_build(mock_func, execution_context):
"""Test build."""
# TODO: add more test cases with @pytest.mark.parametrize

with patch("openbb_core.app.command_runner.ProviderInterface") as mock_pi:
with patch("openbb_core.app.provider_interface.ProviderInterface") as mock_pi:
mock_pi.available_providers = ["provider1", "provider2"]

result = ParametersBuilder.build(
args=(1, 2),
kwargs={
"c": 3,
"d": "4",
"provider_choices": {"provider": ["provider1", "provider2"]},
"provider_choices": {"provider": "provider1"},
},
func=mock_func,
execution_context=execution_context,
route="mock/route",
)

assert result == {
"a": 1,
"b": 2,
"c": 3.0,
"d": 4,
"provider_choices": {"provider": ["provider1", "provider2"]},
"provider_choices": {"provider": "provider1"},
}


Expand Down
2 changes: 1 addition & 1 deletion openbb_platform/core/tests/app/test_provider_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_map(provider_interface):
def test_credentials(provider_interface):
"""Test required credentials."""
credentials = provider_interface.credentials
assert isinstance(credentials, list)
assert isinstance(credentials, dict)
assert len(credentials) > 0


Expand Down
3 changes: 2 additions & 1 deletion openbb_platform/core/tests/provider/test_registry_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def test_get_credentials(load_registry_map):
"""Test if the _get_credentials method behaves as expected."""
required_creds = load_registry_map.credentials

assert "fmp_api_key" in required_creds
assert "fmp" in required_creds
assert required_creds["fmp"] == ["fmp_api_key"]


def test_get_available_providers(load_registry_map):
Expand Down

0 comments on commit faf1180

Please sign in to comment.