def test_handle_move_build_nowait(self): """Test handle_move_build function with --nowait option""" pkgs = ['pkg_a-1.0-1fc26'] arguments = ['tag-a', 'tag-b', '--nowait'] + pkgs task_id = 999 self.session.getBuild.side_effect = [ { 'id': 11, 'name': 'pkg_a', 'version': '1.0', 'release': '1fc26' }, ] self.session.moveBuild.side_effect = [task_id] expected = "Created task %d, moving %s" % (task_id, pkgs[0]) + "\n" with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: rv = handle_move_build(self.options, self.session, arguments) # sanity checks self.assertEqual(rv, None) self.assert_console_message(stdout, expected) self.activate_session.assert_called_with(self.session, self.options) self.session.logout.assert_not_called() self.watch_tasks.assert_not_called()
def test_handle_move_build_with_all_option(self): """Test handle_move_build function with --all option""" pkgs = ['pkg_a-1.0-1fc26', 'pkg_b-2.0-1fc26', 'pkg_c-2.2-2fc26'] arguments = ['tag-a', 'tag-b', '--all', '--nowait'] + pkgs self.session.getPackage.side_effect = [ { 'id': 44, 'name': 'pkg_a', 'version': '1.0', 'release': '1fc26' }, { 'id': 55, 'name': 'pkg_b', 'version': '2.0', 'release': '1fc26' }, {}, # assume pkg_c-2.2-2fc26 is invalid ] self.session.moveAllBuilds.side_effect = [[500, 501, 502], [601, 602, 603]] expected = 'No such package: %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n" with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: rv = handle_move_build(self.options, self.session, arguments) self.assertEqual(rv, None) self.assert_console_message(stdout, expected) self.session.moveAllBuilds.assert_has_calls([ mock.call(arguments[0], arguments[1], p, None) for p in pkgs[:-1] ])
def test_handle_move_build(self): """Test handle_move_build function""" pkgs = ['pkg_a-1.0-1fc26', 'pkg_b-2.0-1fc26', 'pkg_c-2.2-2fc26'] arguments = ['tag-a', 'tag-b'] + pkgs tasks = [202, 303] self.options.quiet = False self.options.force = False self.options.poll_interval = 100 self.session.getBuild.side_effect = [ {'id': 11, 'name': 'pkg_a', 'version': '1.0', 'release': '1fc26'}, {'id': 22, 'name': 'pkg_b', 'version': '2.0', 'release': '1fc26'}, {}, # assume pkg_c-2.2-2fc26 is invalid ] self.session.moveBuild.side_effect = tasks expected = 'Invalid build %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n" for i, t in enumerate(tasks): expected += "Created task %d, moving %s" % (t, pkgs[i]) + "\n" with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: rv = handle_move_build(self.options, self.session, arguments) # sanity checks self.assertEqual(rv, True) self.assert_console_message(stdout, expected) self.activate_session.assert_called_with(self.session, self.options) self.session.logout.assert_called_once() self.watch_tasks.assert_called_with( self.session, tasks, quiet=self.options.quiet, poll_interval=self.options.poll_interval)
def test_handle_move_build_nowait(self): """Test handle_move_build function with --nowait option""" pkgs = ['pkg_a-1.0-1fc26'] arguments = ['tag-a', 'tag-b', '--nowait'] + pkgs task_id = 999 self.session.getBuild.side_effect = [ {'id': 11, 'name': 'pkg_a', 'version': '1.0', 'release': '1fc26'}, ] self.session.moveBuild.side_effect = [task_id] expected = "Created task %d, moving %s" % (task_id, pkgs[0]) + "\n" with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: rv = handle_move_build(self.options, self.session, arguments) # sanity checks self.assertEqual(rv, None) self.assert_console_message(stdout, expected) self.activate_session.assert_called_with(self.session, self.options) self.session.logout.assert_not_called() self.watch_tasks.assert_not_called()
def test_handle_move_build_with_all_option(self): """Test handle_move_build function with --all option""" pkgs = ['pkg_a-1.0-1fc26', 'pkg_b-2.0-1fc26', 'pkg_c-2.2-2fc26'] arguments = ['tag-a', 'tag-b', '--all', '--nowait'] + pkgs self.session.getPackage.side_effect = [ {'id': 44, 'name': 'pkg_a', 'version': '1.0', 'release': '1fc26'}, {'id': 55, 'name': 'pkg_b', 'version': '2.0', 'release': '1fc26'}, {}, # assume pkg_c-2.2-2fc26 is invalid ] self.session.moveAllBuilds.side_effect = [ [500, 501, 502], [601, 602, 603] ] expected = 'Invalid package name %s, skipping.' % 'pkg_c-2.2-2fc26' + "\n" with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout: rv = handle_move_build(self.options, self.session, arguments) self.assertEqual(rv, None) self.assert_console_message(stdout, expected) self.session.moveAllBuilds.assert_has_calls( [mock.call(arguments[0], arguments[1], p, None) for p in pkgs[:-1]] )