File size: 1,668 Bytes
b93364a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""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