def test_handle_edit_multi_host(self, activate_session_mock, stdout): hosts = ['host1', 'host2'] host_infos = [mock.ANY, mock.ANY] arches = 'arch1 arch2' capacity = 0.22 description = 'description' comment = 'comment' args = hosts args.append('--arches=' + arches) args.append('--capacity=' + str(capacity)) args.append('--description=' + description) args.append('--comment=' + comment) kwargs = { 'arches': arches, 'capacity': capacity, 'description': description, 'comment': comment } options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.multiCall.side_effect = [[[info] for info in host_infos], [[True], [True]]] # Run it and check immediate output # args: host1, host2, --arches='arch1 arch2', --capacity=0.22, # --description=description, --comment=comment # expected: success rv = handle_edit_host(options, session, args) actual = stdout.getvalue() expected = 'Edited host1\nEdited host2\n' self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(session, options) self.assertEqual(session.mock_calls, [ call.getHost(hosts[0]), call.getHost(hosts[1]), call.multiCall(strict=True), call.editHost(hosts[0], **kwargs), call.editHost(hosts[1], **kwargs), call.multiCall(strict=True) ]) self.assertNotEqual(rv, 1)
def test_handle_edit_multi_host(self, activate_session_mock, stdout): hosts = ['host1', 'host2'] host_infos = [mock.ANY, mock.ANY] arches = 'arch1 arch2' capacity = 0.22 description = 'description' comment = 'comment' args = hosts args.append('--arches=' + arches) args.append('--capacity=' + str(capacity)) args.append('--description=' + description) args.append('--comment=' + comment) kwargs = {'arches': arches, 'capacity': capacity, 'description': description, 'comment': comment} options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.multiCall.side_effect = [[[info] for info in host_infos], [[True], [True]]] # Run it and check immediate output # args: host1, host2, --arches='arch1 arch2', --capacity=0.22, # --description=description, --comment=comment # expected: success rv = cli.handle_edit_host(options, session, args) actual = stdout.getvalue() expected = 'Edited host1\nEdited host2\n' self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(session) self.assertEqual(session.mock_calls, [call.getHost(hosts[0]), call.getHost(hosts[1]), call.multiCall(strict=True), call.editHost(hosts[0], **kwargs), call.editHost(hosts[1], **kwargs), call.multiCall(strict=True)]) self.assertNotEqual(rv, 1)