Skip to content

Commit

Permalink
fix accessing real example.com in test cases (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiannonskuse authored Feb 14, 2024
1 parent 653a103 commit c25fc29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3530,16 +3530,19 @@ 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

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 {
Expand Down
11 changes: 10 additions & 1 deletion tests/accountAdmin/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import unittest
from unittest.mock import patch
from .. import util
import duo_client.admin


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()

Expand Down

0 comments on commit c25fc29

Please sign in to comment.