Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion massive/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ContractsClient,
)
from .vX import VXClient
from typing import Optional, Any
from typing import Optional, Any, Dict
import os

BASE = "https://api.massive.com"
Expand Down Expand Up @@ -60,6 +60,7 @@ def __init__(
verbose: bool = False,
trace: bool = False,
custom_json: Optional[Any] = None,
connection_pool_kw: Optional[Dict[str, Any]] = None,
):
super().__init__(
api_key=api_key,
Expand All @@ -72,6 +73,7 @@ def __init__(
verbose=verbose,
trace=trace,
custom_json=custom_json,
connection_pool_kw=connection_pool_kw,
)
self.vx = VXClient(
api_key=api_key,
Expand All @@ -84,4 +86,5 @@ def __init__(
verbose=verbose,
trace=trace,
custom_json=custom_json,
connection_pool_kw=connection_pool_kw,
)
2 changes: 2 additions & 0 deletions massive/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
connect_timeout: float,
read_timeout: float,
num_pools: int,
connection_pool_kw: Optional[Dict[str, Any]],
retries: int,
base: str,
pagination: bool,
Expand Down Expand Up @@ -80,6 +81,7 @@ def __init__(
cert_reqs="CERT_REQUIRED",
retries=retry_strategy, # use the customized Retry instance
timeout=self.timeout, # set timeout for each request
**(connection_pool_kw if connection_pool_kw is not None else {}),
)

if verbose:
Expand Down
36 changes: 36 additions & 0 deletions test_rest/test_connection_pool_kw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
import os

sys.path.insert(0, os.path.dirname(__file__))

import unittest
from unittest.mock import patch, MagicMock
from massive import RESTClient


class ConnectionPoolKwTest(unittest.TestCase):
def _make_client(self, **kwargs):
with patch("urllib3.PoolManager") as mock_pm:
mock_pm.return_value = MagicMock()
RESTClient(api_key="test", **kwargs)
return mock_pm

def test_default_no_extra_kwargs(self):
"""connection_pool_kw=None passes no extra kwargs to PoolManager."""
mock_pm = self._make_client()
_, call_kwargs = mock_pm.call_args
self.assertNotIn("connection_pool_kw", call_kwargs)

def test_connection_pool_kw_passed_as_kwargs(self):
"""connection_pool_kw dict is unpacked into PoolManager as kwargs."""
extra = {"maxsize": 20, "block": True}
mock_pm = self._make_client(connection_pool_kw=extra)
_, call_kwargs = mock_pm.call_args
self.assertEqual(call_kwargs["maxsize"], 20)
self.assertEqual(call_kwargs["block"], True)

def test_empty_connection_pool_kw(self):
"""Empty dict connection_pool_kw adds no extra kwargs to PoolManager."""
mock_pm = self._make_client(connection_pool_kw={})
_, call_kwargs = mock_pm.call_args
self.assertNotIn("connection_pool_kw", call_kwargs)
Loading