mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-06-14 04:56:57 +08:00
* stash some changes * add more robust testing * mypy * point PR at V5 * introduce spec file * codespell * test fix * fix workflow environment setup * fix workflow environment setup * fix workflow environment setup * add pyyaml to dependencies * split lint jobs * fix workflow environment setup * fix workflow environment setup * workflow env setup * workflow env setup * clean up code comments * add auth hook entrypoints * codespell * add codegen feature * codespell * move _unpack into dispatchers for consistency with codegen packages * surface nested models in the response * fix missing coverage in CI * socrata updates * test fix * detect plotly output * add --include and --exclude flags from generate-extension command * cap test matrix at python 3.14 * no useless comments * platform controller command description split * merge URL overloads from path params * exclude none and unset from model dump --------- Co-authored-by: deeleeramone <> Co-authored-by: Copilot <copilot@github.com>
81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
"""Test the base platform controller."""
|
|
|
|
from unittest.mock import MagicMock, Mock, patch
|
|
|
|
import pytest
|
|
|
|
from openbb_cli.controllers.base_platform_controller import (
|
|
PlatformController,
|
|
Session,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_controller():
|
|
"""Return a platform controller."""
|
|
session = Session() # noqa: F841
|
|
translators = {"test_command": MagicMock(), "test_menu": MagicMock()} # noqa: F841
|
|
translators["test_command"]._parser = Mock(
|
|
_actions=[Mock(dest="data", choices=[], type=str, nargs=None)]
|
|
)
|
|
translators["test_command"].execute_func = Mock(return_value=Mock())
|
|
translators["test_menu"]._parser = Mock(
|
|
_actions=[Mock(dest="data", choices=[], type=str, nargs=None)]
|
|
)
|
|
translators["test_menu"].execute_func = Mock(return_value=Mock())
|
|
|
|
controller = PlatformController(
|
|
name="test", parent_path=["platform"], translators=translators
|
|
)
|
|
return controller
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_platform_controller_initialization(platform_controller):
|
|
"""Test the initialization of the platform controller."""
|
|
expected_path = "/platform/test/"
|
|
assert expected_path == platform_controller.PATH, (
|
|
"Controller path was not set correctly"
|
|
)
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_command_generation(platform_controller):
|
|
"""Test the generation of commands."""
|
|
command_name = "test_command"
|
|
mock_execute_func = Mock(return_value=(Mock(), None))
|
|
platform_controller.translators[command_name].execute_func = mock_execute_func
|
|
|
|
platform_controller._generate_command_call(
|
|
name=command_name, translator=platform_controller.translators[command_name]
|
|
)
|
|
command_method_name = f"call_{command_name}"
|
|
assert hasattr(platform_controller, command_method_name), (
|
|
"Command method was not created"
|
|
)
|
|
|
|
|
|
@patch(
|
|
"openbb_cli.controllers.base_platform_controller.PlatformController._link_obbject_to_data_processing_commands"
|
|
)
|
|
@patch(
|
|
"openbb_cli.controllers.base_platform_controller.PlatformController._generate_commands"
|
|
)
|
|
@patch(
|
|
"openbb_cli.controllers.base_platform_controller.PlatformController._generate_sub_controllers"
|
|
)
|
|
@pytest.mark.integration
|
|
def test_platform_controller_calls(
|
|
mock_sub_controllers, mock_commands, mock_link_commands
|
|
):
|
|
"""Test the calls of the platform controller."""
|
|
translators = {"test_command": Mock()}
|
|
translators["test_command"].parser = Mock()
|
|
translators["test_command"].execute_func = Mock()
|
|
_ = PlatformController(
|
|
name="test", parent_path=["platform"], translators=translators
|
|
)
|
|
mock_sub_controllers.assert_called_once()
|
|
mock_commands.assert_called_once()
|
|
mock_link_commands.assert_called_once()
|