def test__get_session(self, mock_keystone_get_session): osclient = osclients.OSClient(None, None, None) auth_url = "auth_url" version = "version" import warnings with mock.patch.object(warnings, "warn") as mock_warn: self.assertEqual(mock_keystone_get_session.return_value, osclient._get_session(auth_url, version)) self.assertFalse(mock_warn.called) mock_keystone_get_session.assert_called_once_with(version)
def test__get_endpoint(self, mock_keystone_service_catalog, endpoint_type, service_type, region_name): credential = oscredential.OpenStackCredential( "http://auth_url/v2.0", "user", "pass", endpoint_type=endpoint_type, region_name=region_name) mock_choose_service_type = mock.MagicMock() osclient = osclients.OSClient(credential, {}, mock.MagicMock()) osclient.choose_service_type = mock_choose_service_type mock_url_for = mock_keystone_service_catalog.url_for self.assertEqual(mock_url_for.return_value, osclient._get_endpoint(service_type)) call_args = { "service_type": mock_choose_service_type.return_value, "region_name": region_name } if endpoint_type: call_args["interface"] = endpoint_type mock_url_for.assert_called_once_with(**call_args) mock_choose_service_type.assert_called_once_with(service_type)