Files
OpenBB/cli/integration/test_integration_hub_service.py
Danglewood 9f0d592839 [Feature] Remove Python 3.9 (#7235)
* remove python 3.9 support and code

* black

* more cli lint

* more linting

* more lint

* fix for tests

* docstring grammar police

* add lock to to build function to avoid async import race conditions

* grammar police

* lots more linting

* relock
2025-10-10 23:16:16 +00:00

61 lines
1.6 KiB
Python

"""Integration tests for the hub_service module."""
from unittest.mock import create_autospec, patch
import pytest
import requests
from openbb_cli.controllers.hub_service import upload_routine
from openbb_core.app.model.hub.hub_session import HubSession
# pylint: disable=unused-argument, redefined-outer-name, unused-variable
@pytest.fixture
def auth_header():
"""Return a fake auth header."""
return "Bearer fake_token"
@pytest.fixture
def hub_session_mock():
"""Return a mock HubSession."""
mock = create_autospec(HubSession, instance=True)
mock.username = "TestUser"
return mock
# Fixture for routine data
@pytest.fixture
def routine_data():
"""Return a dictionary with routine data."""
return {
"name": "Test Routine",
"description": "A test routine",
"routine": "print('Hello World')",
"override": False,
"tags": "test",
"public": True,
}
@pytest.mark.integration
def test_upload_routine_timeout(auth_header, routine_data):
"""Test upload_routine with a timeout exception."""
with patch(
"requests.post", side_effect=requests.exceptions.Timeout
) as mocked_post: # noqa: F841
response = upload_routine(auth_header, **routine_data)
assert response is None
@pytest.mark.integration
def test_upload_routine_connection_error(auth_header, routine_data):
"""Test upload_routine with a connection error."""
with patch(
"requests.post", side_effect=requests.exceptions.ConnectionError
) as mocked_post: # noqa: F841
response = upload_routine(auth_header, **routine_data)
assert response is None