def test_handle_remove_channel_help(self, activate_session_mock, stderr, stdout): args = [] options = mock.MagicMock() progname = os.path.basename(sys.argv[0]) or 'koji' # Mock out the xmlrpc server session = mock.MagicMock() # Run it and check immediate output with self.assertRaises(SystemExit) as cm: handle_remove_channel(options, session, args) actual_stdout = stdout.getvalue() actual_stderr = stderr.getvalue() expected_stdout = '' expected_stderr = """Usage: %s remove-channel [options] channel (Specify the --help global option for a list of other help options) %s: error: Incorrect number of arguments """ % (progname, progname) self.assertMultiLineEqual(actual_stdout, expected_stdout) self.assertMultiLineEqual(actual_stderr, expected_stderr) # Finally, assert that things were called as we expected. activate_session_mock.assert_not_called() session.getChannel.assert_not_called() session.removeChannel.assert_not_called() self.assertEqual(cm.exception.code, 2)
def test_handle_remove_channel_help( self, activate_session_mock, stderr, stdout): args = [] options = mock.MagicMock() progname = os.path.basename(sys.argv[0]) or 'koji' # Mock out the xmlrpc server session = mock.MagicMock() # Run it and check immediate output with self.assertRaises(SystemExit) as cm: handle_remove_channel(options, session, args) actual_stdout = stdout.getvalue() actual_stderr = stderr.getvalue() expected_stdout = '' expected_stderr = """Usage: %s remove-channel [options] channel (Specify the --help global option for a list of other help options) %s: error: Incorrect number of arguments """ % (progname, progname) self.assertMultiLineEqual(actual_stdout, expected_stdout) self.assertMultiLineEqual(actual_stderr, expected_stderr) # Finally, assert that things were called as we expected. activate_session_mock.assert_not_called() session.getChannel.assert_not_called() session.removeChannel.assert_not_called() if isinstance(cm.exception, int): self.assertEqual(cm.exception, 2) else: self.assertEqual(cm.exception.code, 2)
def test_handle_remove_channel_no_channel(self, activate_session_mock, stderr): channel_info = None self.session.getChannel.return_value = channel_info with self.assertRaises(SystemExit) as ex: handle_remove_channel(self.options, self.session, [self.channel_name]) self.assertExitCode(ex, 1) actual = stderr.getvalue() expected = 'No such channel: %s\n' % self.channel_name self.assertMultiLineEqual(actual, expected) activate_session_mock.assert_called_once_with(self.session, self.options) self.session.getChannel.assert_called_once_with(self.channel_name) self.session.removeChannel.assert_not_called()
def test_handle_remove_channel_help(self, activate_session_mock, stderr, stdout): with self.assertRaises(SystemExit) as ex: handle_remove_channel(self.options, self.session, []) self.assertExitCode(ex, 2) actual_stdout = stdout.getvalue() actual_stderr = stderr.getvalue() expected_stdout = 'remove-channel is deprecated and will be removed in 1.30\n' expected_stderr = """Usage: %s remove-channel [options] <channel> (Specify the --help global option for a list of other help options) %s: error: Incorrect number of arguments """ % (self.progname, self.progname) self.assertMultiLineEqual(actual_stdout, expected_stdout) self.assertMultiLineEqual(actual_stderr, expected_stderr) activate_session_mock.assert_not_called() self.session.getChannel.assert_not_called() self.session.removeChannel.assert_not_called()
def test_handle_remove_channel_force(self, activate_session_mock, stdout): self.session.getChannel.return_value = self.channel_info rv = handle_remove_channel(self.options, self.session, ['--force', self.channel_name]) actual = stdout.getvalue() expected = 'remove-channel is deprecated and will be removed in 1.30\n' self.assertMultiLineEqual(actual, expected) activate_session_mock.assert_called_once_with(self.session, self.options) self.session.getChannel.assert_called_once_with(self.channel_name) self.session.removeChannel.assert_called_once_with(self.channel_name, force=True) self.assertNotEqual(rv, 1)
def test_handle_remove_channel_no_channel(self, activate_session_mock, stderr): channel = 'channel' channel_info = None args = [channel] options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.getChannel.return_value = channel_info # Run it and check immediate output # args: channel # expected: failed: no such channel with self.assertRaises(SystemExit) as ex: handle_remove_channel(options, session, args) self.assertExitCode(ex, 1) actual = stderr.getvalue() expected = 'No such channel: channel\n' self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(session, options) session.getChannel.assert_called_once_with(channel) session.removeChannel.assert_not_called()
def test_handle_remove_channel(self, activate_session_mock, stdout): channel = 'channel' channel_info = mock.ANY args = [channel] options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.getChannel.return_value = channel_info # Run it and check immediate output # args: channel # expected: success rv = handle_remove_channel(options, session, args) actual = stdout.getvalue() expected = '' self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(session, options) session.getChannel.assert_called_once_with(channel) session.removeChannel.assert_called_once_with(channel, force=None) self.assertNotEqual(rv, 1)
def test_handle_remove_channel(self, activate_session_mock, stdout): channel = 'channel' channel_info = mock.ANY args = [channel] options = mock.MagicMock() # Mock out the xmlrpc server session = mock.MagicMock() session.getChannel.return_value = channel_info # Run it and check immediate output # args: channel # expected: success rv = handle_remove_channel(options, session, args) actual = stdout.getvalue() expected = '' self.assertMultiLineEqual(actual, expected) # Finally, assert that things were called as we expected. activate_session_mock.assert_called_once_with(session, options) session.getChannel.assert_called_once_with(channel) session.removeChannel.assert_called_once_with(channel, force=None) self.assertNotEqual(rv, 1)