Example #1
0
 def test_edit_target_without_option(self, stderr):
     expected = "Usage: %s edit-target [options] <name>\n" \
                "(Specify the --help global option for a list of other help options)\n\n" \
                "%s: error: Please specify a build target\n" % (self.progname, self.progname)
     with self.assertRaises(SystemExit) as ex:
         handle_edit_target(self.options, self.session, [])
     self.assertExitCode(ex, 2)
     self.assert_console_message(stderr, expected)
Example #2
0
 def test_edit_target_non_exist_target(self):
     target = 'test-target'
     expected = "No such build target: %s" % target
     self.session.getBuildTarget.return_value = None
     with self.assertRaises(koji.GenericError) as cm:
         handle_edit_target(self.options, self.session, [target])
     self.assertEqual(expected, str(cm.exception))
     self.session.getTag.assert_not_called()
     self.session.editBuildTarget.assert_not_called()
Example #3
0
 def test_edit_target_non_exist_dest_tag(self, stderr):
     target = 'test-target'
     dest_tag = 'test-dest-tag'
     expected = "No such destination tag: %s\n" % dest_tag
     self.session.getTag.return_value = None
     with self.assertRaises(SystemExit) as ex:
         handle_edit_target(self.options, self.session, ['--dest-tag', dest_tag, target])
     self.assertExitCode(ex, 1)
     self.assert_console_message(stderr, expected)
     self.session.editBuildTarget.assert_not_called()
Example #4
0
 def test_edit_target_non_exist_build_tag(self, stderr):
     target = 'test-target'
     new_build_tag = 'new-build-tag'
     self.session.getBuildTarget.return_value = self.build_target_info
     self.session.getTag.return_value = None
     with self.assertRaises(SystemExit) as ex:
         handle_edit_target(self.options, self.session,
                            ['--build-tag', new_build_tag, target])
     self.assertExitCode(ex, 1)
     expected_msg = "No such tag: %s\n" % new_build_tag
     self.assert_console_message(stderr, expected_msg)
     self.session.getTag.assert_called_once_with(new_build_tag)
     self.session.getBuildTarget.assert_called_once_with(target)
     self.session.editBuildTarget.assert_not_called()
Example #5
0
    def test_edit_target_without_perms(self, stderr):
        side_effect_result = [False, False]

        target = 'test-target'
        self.session.hasPerm.side_effect = side_effect_result
        with self.assertRaises(SystemExit) as ex:
            handle_edit_target(self.options, self.session, [target])
        self.assertExitCode(ex, 2)
        expected_msg = """Usage: %s edit-target [options] <name>
(Specify the --help global option for a list of other help options)

%s: error: This action requires target or admin privileges
""" % (self.progname, self.progname)
        self.assert_console_message(stderr, expected_msg)
        self.session.editBuildTarget.assert_not_called()
        self.session.getBuildTarget.assert_not_called()
Example #6
0
 def test_edit_target_tag_arch_none(self, stderr):
     target = 'test-target'
     new_build_tag = 'new-build-tag'
     build_tag_info = copy.deepcopy(self.build_tag_info)
     build_tag_info['arches'] = ''
     self.session.getBuildTarget.return_value = self.build_target_info
     self.session.getTag.return_value = build_tag_info
     with self.assertRaises(SystemExit) as ex:
         handle_edit_target(self.options, self.session,
                            ['--build-tag', new_build_tag, target])
     self.assertExitCode(ex, 1)
     expected_msg = "Build tag has no arches: %s\n" % new_build_tag
     self.assert_console_message(stderr, expected_msg)
     self.session.getTag.assert_called_once_with(new_build_tag)
     self.session.getBuildTarget.assert_called_once_with(target)
     self.session.editBuildTarget.assert_not_called()
Example #7
0
 def test_edit_target_new_name(self, stdout):
     target = 'test-target'
     new_target_name = 'new-test-target'
     self.session.getBuildTarget.return_value = self.build_target_info
     rv = handle_edit_target(self.options, self.session,
                             ['--rename', new_target_name, target])
     self.assertEqual(rv, None)
     expected_msg = ''
     self.assert_console_message(stdout, expected_msg)
     self.session.getTag.assert_not_called()
     self.session.getBuildTarget.assert_called_once_with(target)
     self.session.editBuildTarget.assert_called_once_with(
         self.build_target_info['orig_name'], new_target_name,
         self.build_target_info['build_tag_name'],
         self.build_target_info['dest_tag_name'])