From cd84edd2bec0e71d9a7f83c6fe1b9ab9b18fcecf Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Thu, 8 Oct 2015 17:06:02 +0100 Subject: [PATCH] Mock keystone call to avoid test failure The test test_password_prompted() was expecting a keystone failure, but because of an error in the requests/urllib3 library it was returning a different exception and causing our tests to fail, see[1]. Independent of the the problem above on tests we should not rely on some external library failing like that, we should mock this failures to make our tests more reliable and that's what this patch is doing. [1] https://bugs.launchpad.net/ospurge/+bug/1503768 Change-Id: I3e6091eb2bc221a16fdc18b998ba138058818894 Closes-Bug: #1504197 (cherry picked from commit 42d52af3c2238900eb69217bba5dbbcdca63abf0) --- ironicclient/tests/unit/test_shell.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ironicclient/tests/unit/test_shell.py b/ironicclient/tests/unit/test_shell.py index 80ffcc526..37650a199 100644 --- a/ironicclient/tests/unit/test_shell.py +++ b/ironicclient/tests/unit/test_shell.py @@ -119,13 +119,28 @@ class ShellTest(utils.BaseTestCase): self.make_env(exclude='OS_USERNAME') self.test_help() + @mock.patch.object(ironic_shell.IronicShell, '_get_keystone_auth', + side_effect=keystone_exc.ConnectionRefused) @mock.patch('sys.stdin', side_effect=mock.MagicMock) @mock.patch('getpass.getpass', return_value='password') - def test_password_prompted(self, mock_getpass, mock_stdin): + def test_password_prompted(self, mock_getpass, mock_stdin, mock_ks): self.make_env(exclude='OS_PASSWORD') # We will get a Connection Refused because there is no keystone. self.assertRaises(keystone_exc.ConnectionRefused, self.shell, 'node-list') + expected_kwargs = { + 'username': FAKE_ENV['OS_USERNAME'], + 'user_domain_id': '', + 'user_domain_name': '', + 'password': FAKE_ENV['OS_PASSWORD'], + 'auth_token': '', + 'project_id': '', + 'project_name': FAKE_ENV['OS_TENANT_NAME'], + 'project_domain_id': '', + 'project_domain_name': '', + } + mock_ks.assert_called_once_with(mock.ANY, FAKE_ENV['OS_AUTH_URL'], + **expected_kwargs) # Make sure we are actually prompted. mock_getpass.assert_called_with('OpenStack Password: ')