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
This commit is contained in:
parent
6d5779d07e
commit
42d52af3c2
|
@ -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: ')
|
||||
|
||||
|
|
Loading…
Reference in New Issue