Blame tests/cli/commands/test_group.py

Packit 6f3914
# -*- coding: utf-8 -*-
Packit 6f3914
Packit 6f3914
# Copyright (C) 2014-2018 Red Hat, Inc.
Packit 6f3914
#
Packit 6f3914
# This copyrighted material is made available to anyone wishing to use,
Packit 6f3914
# modify, copy, or redistribute it subject to the terms and conditions of
Packit 6f3914
# the GNU General Public License v.2, or (at your option) any later version.
Packit 6f3914
# This program is distributed in the hope that it will be useful, but WITHOUT
Packit 6f3914
# ANY WARRANTY expressed or implied, including the implied warranties of
Packit 6f3914
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit 6f3914
# Public License for more details.  You should have received a copy of the
Packit 6f3914
# GNU General Public License along with this program; if not, write to the
Packit 6f3914
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 6f3914
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
Packit 6f3914
# source code or documentation are not subject to the GNU General Public
Packit 6f3914
# License and may only be used or replicated with the express permission of
Packit 6f3914
# Red Hat, Inc.
Packit 6f3914
#
Packit 6f3914
Packit 6f3914
from __future__ import absolute_import
Packit 6f3914
Packit 6f3914
import dnf.cli.commands.group as group
Packit 6f3914
import dnf.comps
Packit 6f3914
import dnf.exceptions
Packit 6f3914
from dnf.comps import CompsQuery
Packit 6f3914
from dnf.cli.option_parser import OptionParser
Packit 6f3914
Packit 6f3914
import tests.support
Packit 6f3914
Packit 6f3914
Packit 6f3914
class GroupCommandStaticTest(tests.support.TestCase):
Packit 6f3914
Packit 6f3914
    def test_canonical(self):
Packit 6f3914
        cmd = group.GroupCommand(tests.support.mock.MagicMock())
Packit 6f3914
Packit 6f3914
        for args, out in [
Packit 6f3914
                (['grouplist', 'crack'], ['list', 'crack']),
Packit 6f3914
                (['groups'], ['summary']),
Packit 6f3914
                (['group', 'info', 'crack'], ['info', 'crack']),
Packit 6f3914
                (['group', 'update', 'crack'], ['upgrade', 'crack'])]:
Packit 6f3914
            parser = OptionParser()
Packit 6f3914
            parser.parse_main_args(args)
Packit 6f3914
            parser.parse_command_args(cmd, args)
Packit 6f3914
            cmd._canonical()
Packit 6f3914
            self.assertEqual(cmd.opts.subcmd, out[0])
Packit 6f3914
            self.assertEqual(cmd.opts.args, out[1:])
Packit 6f3914
Packit 6f3914
    def test_split_extcmds(self):
Packit 6f3914
        cmd = group.GroupCommand(tests.support.mock.MagicMock())
Packit 6f3914
        cmd.base.conf = dnf.conf.Conf()
Packit 6f3914
        tests.support.command_run(cmd, ['install', 'crack'])
Packit 6f3914
        cmd.base.env_group_install.assert_called_with(
Packit 6f3914
            ['crack'], ('mandatory', 'default', 'conditional'),
Packit 6f3914
            cmd.base.conf.strict)
Packit 6f3914
Packit 6f3914
Packit 6f3914
class GroupCommandTest(tests.support.DnfBaseTestCase):
Packit 6f3914
Packit 6f3914
    REPOS = ["main"]
Packit 6f3914
    COMPS = True
Packit 6f3914
    INIT_SACK = True
Packit 6f3914
Packit 6f3914
    def setUp(self):
Packit 6f3914
        super(GroupCommandTest, self).setUp()
Packit 6f3914
        self.cmd = group.GroupCommand(self.base.mock_cli())
Packit 6f3914
        self.parser = OptionParser()
Packit 6f3914
Packit 6f3914
    def test_environment_list(self):
Packit 6f3914
        env_inst, env_avail = self.cmd._environment_lists(['sugar*'])
Packit 6f3914
        self.assertLength(env_inst, 0)
Packit 6f3914
        self.assertLength(env_avail, 1)
Packit 6f3914
        self.assertEqual(env_avail[0].name, 'Sugar Desktop Environment')
Packit 6f3914
Packit 6f3914
    def test_configure(self):
Packit 6f3914
        tests.support.command_configure(self.cmd, ['remove', 'crack'])
Packit 6f3914
        demands = self.cmd.cli.demands
Packit 6f3914
        self.assertTrue(demands.allow_erasing)
Packit 6f3914
        self.assertFalse(demands.freshest_metadata)
Packit 6f3914
Packit 6f3914
Packit 6f3914
class CompsQueryTest(tests.support.DnfBaseTestCase):
Packit 6f3914
Packit 6f3914
    REPOS = []
Packit 6f3914
    COMPS = True
Packit 6f3914
Packit 6f3914
    def test_all(self):
Packit 6f3914
        status_all = CompsQuery.AVAILABLE | CompsQuery.INSTALLED
Packit 6f3914
        kinds_all = CompsQuery.ENVIRONMENTS | CompsQuery.GROUPS
Packit 6f3914
        q = CompsQuery(self.comps, self.history, kinds_all, status_all)
Packit 6f3914
Packit 6f3914
        res = q.get('sugar*', '*er*')
Packit 6f3914
        self.assertCountEqual(res.environments,
Packit 6f3914
                              ('sugar-desktop-environment',))
Packit 6f3914
        self.assertCountEqual(res.groups, ("Peppers", 'somerset'))
Packit 6f3914
Packit 6f3914
    def test_err(self):
Packit 6f3914
        q = CompsQuery(self.comps, self.history, CompsQuery.ENVIRONMENTS,
Packit 6f3914
                       CompsQuery.AVAILABLE)
Packit 6f3914
        with self.assertRaises(dnf.exceptions.CompsError):
Packit 6f3914
            q.get('*er*')
Packit 6f3914
Packit 6f3914
    def test_installed(self):
Packit 6f3914
        q = CompsQuery(self.comps, self.history, CompsQuery.GROUPS,
Packit 6f3914
                       CompsQuery.INSTALLED)
Packit 6f3914
        self.base.read_mock_comps(False)
Packit 6f3914
        grp = self.base.comps.group_by_pattern('somerset')
Packit 6f3914
        self.base.group_install(grp.id, ('mandatory',))
Packit 6f3914
Packit 6f3914
        self._swdb_commit()
Packit 6f3914
Packit 6f3914
        res = q.get('somerset')
Packit 6f3914
        self.assertEmpty(res.environments)
Packit 6f3914
        grp_ids = list(res.groups)
Packit 6f3914
        self.assertCountEqual(grp_ids, ('somerset',))