def test_anon_handle_wait_repo_target_not_found(self, stdout): """Test anon_handle_wait_repo function on target not found cases""" # Case 1. both build and dest targets are not found self.session.getTag.return_value = self.TAG.copy() self.session.getBuildTargets.return_value = [] rv = anon_handle_wait_repo(self.options, self.session, [self.tag_name]) self.assertEqual(rv, 1) expected = "%(name)s is not a build tag for any target" % self.TAG + "\n" self.assert_console_message(stdout, expected) # Cas 2. dest is matched, show suggestion self.session.getBuildTargets.side_effect = [ [], [ {'build_tag_name': 'build-tag-1'}, {'build_tag_name': 'build-tag-2'}, {'build_tag_name': 'build-tag-3'}, ], ] rv = anon_handle_wait_repo(self.options, self.session, [self.tag_name]) self.assertEqual(rv, 1) expected = "%(name)s is not a build tag for any target" % self.TAG + "\n" expected += "Suggested tags: build-tag-1, build-tag-2, build-tag-3\n" self.assert_console_message(stdout, expected)
def test_anon_handle_wait_repo_target_not_found(self, stdout): """Test anon_handle_wait_repo function on target not found cases""" # Case 1. both build and dest targets are not found self.session.getTag.return_value = self.TAG.copy() self.session.getBuildTargets.return_value = [] rv = anon_handle_wait_repo(self.options, self.session, [self.tag_name]) self.assertEqual(rv, 1) expected = "%(name)s is not a build tag for any target" % self.TAG + "\n" self.assert_console_message(stdout, expected) # Cas 2. dest is matched, show suggestion self.session.getBuildTargets.side_effect = [ [], [ { 'build_tag_name': 'build-tag-1' }, { 'build_tag_name': 'build-tag-2' }, { 'build_tag_name': 'build-tag-3' }, ], ] rv = anon_handle_wait_repo(self.options, self.session, [self.tag_name]) self.assertEqual(rv, 1) expected = "%(name)s is not a build tag for any target" % self.TAG + "\n" expected += "Suggested tags: build-tag-1, build-tag-2, build-tag-3\n" self.assert_console_message(stdout, expected)
def handle_add_sidetag(options, session, args): "Create sidetag" usage = _("%(prog)s add-sidetag [options] <basetag>") usage += _( "\n(Specify the --help global option for a list of other help options)" ) parser = ArgumentParser(usage=usage) parser.add_argument("basetag", help="name of basetag") parser.add_argument( "-q", "--quiet", action="store_true", help=_("Do not print tag name"), default=options.quiet, ) parser.add_argument("-w", "--wait", action="store_true", help=_("Wait until repo is ready.")) parser.add_argument("--debuginfo", action="store_true", help=_("Buildroot repo will contain debuginfos")) parser.add_argument("--suffix", action="store", help=_("Suffix from hub-supported ones")) opts = parser.parse_args(args) activate_session(session, options) kwargs = {"debuginfo": opts.debuginfo} if opts.suffix: kwargs['suffix'] = opts.suffix try: tag = session.createSideTag(opts.basetag, **kwargs) except koji.ActionNotAllowed: parser.error(_("Policy violation")) except koji.ParameterError as ex: if 'suffix' in str(ex): parser.error( _("Hub is older and doesn't support --suffix, please run it without it" )) else: raise if not opts.quiet: print(tag["name"]) if opts.wait: args = ["--target", tag["name"]] if opts.quiet: args.append("--quiet") anon_handle_wait_repo(options, session, args)
def __test_wait_repo_timeout(self, args, expected, stderr, stdout, time_mock, ret_code=0): self.options.quiet = False time_mock.side_effect = [0, 61, 62] if ret_code: with self.assertRaises(SystemExit) as ex: anon_handle_wait_repo(self.options, self.session, args + ['--timeout', '1']) self.assertExitCode(ex, ret_code) self.assert_console_message(stderr, expected) self.assert_console_message(stdout, '') else: rv = anon_handle_wait_repo(self.options, self.session, args + ['--timeout', '1']) self.assert_console_message(stdout, expected) self.assert_console_message(stderr, '') self.assertIn(rv, [0, None])
def handle_add_sidetag(options, session, args): "Create sidetag" usage = _("%(prog)s add-sidetag [options] <basetag>") usage += _( "\n(Specify the --help global option for a list of other help options)" ) parser = ArgumentParser(usage=usage) parser.add_argument("basetag", help="name of basetag") parser.add_argument( "-q", "--quiet", action="store_true", help=_("Do not print tag name"), default=options.quiet, ) parser.add_argument("-w", "--wait", action="store_true", help=_("Wait until repo is ready.")) parser.add_argument("--debuginfo", action="store_true", help=_("Buildroot repo will contain debuginfos")) opts = parser.parse_args(args) activate_session(session, options) try: tag = session.createSideTag(opts.basetag, debuginfo=opts.debuginfo) except koji.ActionNotAllowed: parser.error(_("Policy violation")) if not opts.quiet: print(tag["name"]) if opts.wait: args = ["--target", tag["name"]] if opts.quiet: args.append("--quiet") anon_handle_wait_repo(options, session, args)
def __test_wait_repo_timeout(self, args, expected, stdout, time_mock): self.options.quiet = False time_mock.side_effect = [0, 61, 62] anon_handle_wait_repo(self.options, self.session, args + ['--timeout', '1']) self.assert_console_message(stdout, expected)
def __test_wait_repo(self, args, expected, stdout, time_mock): self.options.quiet = False time_mock.side_effect = [0, 1, 2, 3] anon_handle_wait_repo(self.options, self.session, args) self.assert_console_message(stdout, expected)