Skip to content

Commit

Permalink
Merge pull request #268 from amcmahon-rh/transport_args
Browse files Browse the repository at this point in the history
Add  transport args as a kwarg for HubProxy [RHELDST-27818]
  • Loading branch information
rohanpm authored Nov 25, 2024
2 parents be7b4bd + 200c1e9 commit 0568cce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kobo/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class ClientCommand(kobo.cli.Command):
class HubProxy(object):
"""A Hub client (thin ServerProxy wrapper)."""

def __init__(self, conf, client_type=None, logger=None, transport=None, auto_logout=None, **kwargs):
def __init__(self, conf, client_type=None, logger=None, transport=None,
auto_logout=None, transport_args=None, **kwargs):
self._conf = kobo.conf.PyConfigParser()
self._hub = None

Expand Down Expand Up @@ -157,7 +158,7 @@ def __init__(self, conf, client_type=None, logger=None, transport=None, auto_log
if transport is not None:
self._transport = transport
else:
transport_args = {}
transport_args = transport_args or {}
if self._hub_url.startswith("https://"):
TransportClass = kobo.xmlrpc.retry_request_decorator(kobo.xmlrpc.SafeCookieTransport)
if hasattr(ssl, 'create_default_context'):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_hubproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,18 @@ def test_proxies_to_xmlrpc(requests_session):
# Last call should have invoked the method I requested
(_, request_xml) = transport.fake_transport_calls[-1]
assert b'some_obj.some_method' in request_xml


def test_pass_transport_args(requests_session):
"""HubProxy proxies to underlying XML-RPC ServerProxy"""
conf = PyConfigParser()
conf.load_from_dict({"HUB_URL": 'https://example.com/hub'})
transport_args = {"retry_count": 2, "retry_timeout": 45}
with mock.patch(
"kobo.xmlrpc.SafeCookieTransport") as mock_transport_class, mock.patch(
"kobo.xmlrpc.retry_request_decorator",
return_value=mock_transport_class):
HubProxy(conf, transport_args=transport_args)
mock_transport_class.assert_called_with(context=mock.ANY,
retry_count=2,
retry_timeout=45)

0 comments on commit 0568cce

Please sign in to comment.