Fix test for barbican cached client

Test is broken after Change Ibfaea3fe9e394f6b1286d92437629d0400305968 in
barbicanclient. As this test mock keystoneclient, version discovery by
barbicanclient using the MagicMock keystone session now fails.

As this test just wants to make sure we are using a cached
barbicanclient, it should be safe to mock barbicanclient and check that
the client is only initialised once.

Change-Id: I85e70ea637af9c0b467aa32baf107d7fbed914c0
This commit is contained in:
Jake Yip 2023-02-23 18:17:16 +11:00
parent 4dad26bf53
commit d363622bf9
1 changed files with 5 additions and 1 deletions

View File

@ -220,8 +220,9 @@ class ClientsTest(base.BaseTestCase):
self.assertRaises(exception.AuthorizationFailure, obj.barbican)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(barbicanclient, 'Client')
@mock.patch.object(clients.OpenStackClients, 'url_for')
def test_clients_barbican_cached(self, mock_url, mock_keystone):
def test_clients_barbican_cached(self, mock_url, mock_call, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
mock_url.return_value = "url_from_keystone"
@ -233,6 +234,9 @@ class ClientsTest(base.BaseTestCase):
barbican = obj.barbican()
barbican_cached = obj.barbican()
self.assertEqual(barbican, barbican_cached)
mock_call.assert_called_once_with(
endpoint='url_from_keystone',
session=keystone.session)
@mock.patch.object(novaclient, 'Client')
@mock.patch.object(clients.OpenStackClients, 'keystone')