Stop mocking keystoneauth internals

The unittests do some mocks of the keystoneauth Session contructor to
make sure Sessions are being constructed properly. In keystoneauth 3.7.0
we added two new options that can be used from oslo.config files, and
those options in turn now get passed to the Session constructor - which
breaks the mocks.

The thing is, neutron doesn't need to test that
load_session_from_conf_options works, keystoneauth tests that. What we
want to test here is that setting various config options has a specific
result. So instead of testing the entire args list (which could change)
test for the specific results we're concerned about.

Change-Id: I3048cdb8f8b07f6b243a0ab7d08484278c60995f
Needed-By: https://review.openstack.org/569447
This commit is contained in:
Monty Taylor 2018-05-19 07:52:17 -05:00 committed by Slawek Kaplonski
parent 685fed22e7
commit e982506c20
2 changed files with 19 additions and 18 deletions

View File

@ -2300,16 +2300,17 @@ class PlacementAPIClientTestCase(base.DietTestCase):
self.mock_request = self.mock_request_p.start()
self.client = placement_client.PlacementAPIClient()
@mock.patch('keystoneauth1.session.Session')
@mock.patch('keystoneauth1.loading.load_session_from_conf_options')
@mock.patch('keystoneauth1.loading.load_auth_from_conf_options')
def test_constructor(self, load_auth_mock, ks_sess_mock):
def test_constructor(self, load_auth_mock, load_sess_mock):
mock_auth = mock.Mock()
load_auth_mock.return_value = mock_auth
placement_client.PlacementAPIClient()
load_auth_mock.assert_called_once_with(cfg.CONF, 'placement')
ks_sess_mock.assert_called_once_with(auth=load_auth_mock.return_value,
cert=None,
timeout=None,
verify=True)
load_sess_mock.assert_called_once_with(
cfg.CONF, 'placement', auth=mock_auth)
def test_create_resource_provider(self):
expected_payload = 'fake_resource_provider'

View File

@ -804,9 +804,9 @@ class TestDesignateClientKeystoneV2(testtools.TestCase):
True,
group='designate')
driver.get_clients(self.TEST_CONTEXT)
self.driver_session.assert_called_with(cert=None,
timeout=None,
verify=False)
args, kwargs = self.driver_session.call_args
self.assertIn('verify', kwargs)
self.assertFalse(kwargs['verify'], False)
def test_secure_client(self):
cfg.CONF.set_override('insecure',
@ -816,9 +816,9 @@ class TestDesignateClientKeystoneV2(testtools.TestCase):
self.TEST_CA_CERT,
group='designate')
driver.get_clients(self.TEST_CONTEXT)
self.driver_session.assert_called_with(cert=None,
timeout=None,
verify=self.TEST_CA_CERT)
args, kwargs = self.driver_session.call_args
self.assertIn('verify', kwargs)
self.assertEqual(kwargs['verify'], self.TEST_CA_CERT)
def test_auth_type_not_defined(self):
driver.get_clients(self.TEST_CONTEXT)
@ -892,9 +892,9 @@ class TestDesignateClientKeystoneV3(testtools.TestCase):
True,
group='designate')
driver.get_clients(self.TEST_CONTEXT)
self.driver_session.assert_called_with(cert=None,
timeout=None,
verify=False)
args, kwargs = self.driver_session.call_args
self.assertIn('verify', kwargs)
self.assertFalse(kwargs['verify'], False)
def test_secure_client(self):
cfg.CONF.set_override('insecure',
@ -904,9 +904,9 @@ class TestDesignateClientKeystoneV3(testtools.TestCase):
self.TEST_CA_CERT,
group='designate')
driver.get_clients(self.TEST_CONTEXT)
self.driver_session.assert_called_with(cert=None,
timeout=None,
verify=self.TEST_CA_CERT)
args, kwargs = self.driver_session.call_args
self.assertIn('verify', kwargs)
self.assertEqual(kwargs['verify'], self.TEST_CA_CERT)
def test_auth_type_password(self):
driver.get_clients(self.TEST_CONTEXT)