Blame tests/test_repomanage.py

Packit Service 27f74b
# Copyright (C) 2015 Igor Gnatenko
Packit Service 27f74b
#
Packit Service 27f74b
# This copyrighted material is made available to anyone wishing to use,
Packit Service 27f74b
# modify, copy, or redistribute it subject to the terms and conditions of
Packit Service 27f74b
# the GNU General Public License v.2, or (at your option) any later version.
Packit Service 27f74b
# This program is distributed in the hope that it will be useful, but WITHOUT
Packit Service 27f74b
# ANY WARRANTY expressed or implied, including the implied warranties of
Packit Service 27f74b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit Service 27f74b
# Public License for more details.  You should have received a copy of the
Packit Service 27f74b
# GNU General Public License along with this program; if not, write to the
Packit Service 27f74b
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 27f74b
# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
Packit Service 27f74b
# source code or documentation are not subject to the GNU General Public
Packit Service 27f74b
# License and may only be used or replicated with the express permission of
Packit Service 27f74b
# Red Hat, Inc.
Packit Service 27f74b
#
Packit Service 27f74b
Packit Service 27f74b
from __future__ import absolute_import
Packit Service 27f74b
from __future__ import unicode_literals
Packit Service 27f74b
from tests.support import mock
Packit Service 27f74b
Packit Service 27f74b
import dnf.pycomp
Packit Service 27f74b
import os
Packit Service 27f74b
import repomanage
Packit Service 27f74b
import tests.support as support
Packit Service 27f74b
Packit Service 27f74b
Packit Service 27f74b
class TestRepoManageFunctions(support.TestCase):
Packit Service 27f74b
Packit Service 27f74b
    def setUp(self):
Packit Service 27f74b
        self.cmd = repomanage.RepoManageCommand(
Packit Service 27f74b
            support.CliStub(support.BaseStub()))
Packit Service 27f74b
        self.path = os.path.join(os.path.dirname(__file__), "resources/repomanage/")
Packit Service 27f74b
Packit Service 27f74b
    @staticmethod
Packit Service 27f74b
    def _path_join_in_list(l, path):
Packit Service 27f74b
        return [os.path.join(path, x) for x in l]
Packit Service 27f74b
Packit Service 27f74b
    def test_old_option(self):
Packit Service 27f74b
        args = ["--old", self.path]
Packit Service 27f74b
        with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
Packit Service 27f74b
            support.command_run(self.cmd, args)
Packit Service 27f74b
            expected_list = ["foo-4-6.src.rpm",
Packit Service 27f74b
                             "foo-4-7.src.rpm",
Packit Service 27f74b
                             "noarch/foo-4-6.noarch.rpm",
Packit Service 27f74b
                             "noarch/foo-4-7.noarch.rpm"]
Packit Service 27f74b
            self.assertEqual(stdout.getvalue().split(),
Packit Service 27f74b
                             self._path_join_in_list(expected_list, self.path))
Packit Service 27f74b
Packit Service 27f74b
    def test_new_option(self):
Packit Service 27f74b
        args = ["--new", self.path]
Packit Service 27f74b
        with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
Packit Service 27f74b
            support.command_run(self.cmd, args)
Packit Service 27f74b
            expected_list = ["foo-4-8.src.rpm",
Packit Service 27f74b
                             "noarch/foo-4-8.noarch.rpm"]
Packit Service 27f74b
            self.assertEqual(stdout.getvalue().split(),
Packit Service 27f74b
                             self._path_join_in_list(expected_list, self.path))
Packit Service 27f74b
Packit Service 27f74b
    def test_keep_option(self):
Packit Service 27f74b
        args = ["--new", "--keep", "2", self.path]
Packit Service 27f74b
        with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
Packit Service 27f74b
            support.command_run(self.cmd, args)
Packit Service 27f74b
            expected_list = ["foo-4-7.src.rpm",
Packit Service 27f74b
                             "foo-4-8.src.rpm",
Packit Service 27f74b
                             "noarch/foo-4-7.noarch.rpm",
Packit Service 27f74b
                             "noarch/foo-4-8.noarch.rpm"]
Packit Service 27f74b
            self.assertEqual(stdout.getvalue().split(),
Packit Service 27f74b
                             self._path_join_in_list(expected_list, self.path))
Packit Service 27f74b
Packit Service 27f74b
    def test_space_option(self):
Packit Service 27f74b
        args = ["--new", "--space", self.path]
Packit Service 27f74b
        with mock.patch("sys.stdout", new_callable=dnf.pycomp.StringIO) as stdout:
Packit Service 27f74b
            support.command_run(self.cmd, args)
Packit Service 27f74b
            expected_list = ["foo-4-8.src.rpm",
Packit Service 27f74b
                             "noarch/foo-4-8.noarch.rpm"]
Packit Service 27f74b
            self.assertEqual(stdout.getvalue()[:-1],
Packit Service 27f74b
                             " ".join(self._path_join_in_list(expected_list, self.path)))