diff --git a/duo_client/admin.py b/duo_client/admin.py index 490e14b..6fb5b6c 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -3530,9 +3530,7 @@ def __init__(self, account_id, child_api_host=None, **kwargs): if child_api_host is None: child_api_host = kwargs.get('host') try: - accounts_api = Accounts(**kwargs) - accounts_api.get_child_accounts() - child_api_host = Accounts.child_map.get(account_id, kwargs['host']) + child_api_host = self.get_child_api_host(account_id, **kwargs) except RuntimeError: pass kwargs['host'] = child_api_host @@ -3540,6 +3538,11 @@ def __init__(self, account_id, child_api_host=None, **kwargs): super(AccountAdmin, self).__init__(**kwargs) self.account_id = account_id + def get_child_api_host(self, account_id, **kwargs): + accounts_api = Accounts(**kwargs) + accounts_api.get_child_accounts() + return Accounts.child_map.get(account_id, kwargs['host']) + def get_edition(self): """ Returns the edition of the account { diff --git a/tests/accountAdmin/base.py b/tests/accountAdmin/base.py index ebc0eda..8a7010e 100644 --- a/tests/accountAdmin/base.py +++ b/tests/accountAdmin/base.py @@ -1,4 +1,5 @@ import unittest +from unittest.mock import patch from .. import util import duo_client.admin @@ -6,9 +7,17 @@ class TestAccountAdmin(unittest.TestCase): def setUp(self): - kwargs = {'ikey': 'test_ikey', 'skey': 'test_skey', 'host': 'example.com', 'child_api_host': 'example2.com'} + child_host = 'example2.com' + kwargs = {'ikey': 'test_ikey', 'skey': 'test_skey', 'host': 'example.com'} + + patcher = patch("duo_client.admin.AccountAdmin.get_child_api_host") + self.mock_child_host = patcher.start() + self.mock_child_host.return_value = child_host + self.addCleanup(patcher.stop) + self.client = duo_client.admin.AccountAdmin( 'DA012345678901234567', **kwargs) + # monkeypatch client's _connect() self.client._connect = lambda: util.MockHTTPConnection()