Beispiel #1
0
    def test_unrar(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.unrar(
                '/tmp/rarfile.rar',
                '/home/strongbad/',
                excludes='file_1,file_2'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unrar', 'x', '-idp', '/tmp/rarfile.rar',
                 '-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
                runas=None, python_shell=False, template=None
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.unrar(
                '/tmp/rarfile.rar',
                '/home/strongbad/',
                excludes=['file_1', 'file_2']
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                ['unrar', 'x', '-idp', '/tmp/rarfile.rar',
                 '-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
                runas=None, python_shell=False, template=None
            )
Beispiel #2
0
    def test_unrar(self):
        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.unrar(
                '/tmp/rarfile.rar',
                '/home/strongbad/',
                excludes='file_1,file_2'
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                'unrar x -idp /tmp/rarfile.rar '
                '-x file_1 -x file_2 /home/strongbad/',
                template=None
            )

        mock = MagicMock(return_value='salt')
        with patch.dict(archive.__salt__, {'cmd.run': mock}):
            ret = archive.unrar(
                '/tmp/rarfile.rar',
                '/home/strongbad/',
                excludes=['file_1', 'file_2']
            )
            self.assertEqual(['salt'], ret)
            mock.assert_called_once_with(
                'unrar x -idp /tmp/rarfile.rar '
                '-x file_1 -x file_2 /home/strongbad/',
                template=None
            )
Beispiel #3
0
    def test_unrar(self):
        with patch('salt.utils.path.which_bin', lambda exe: exe[0] if isinstance(exe, (list, tuple)) else exe):
            with patch('salt.utils.path.which', lambda exe: exe[0] if isinstance(exe, (list, tuple)) else exe):
                mock = MagicMock(return_value='salt')
                with patch.dict(archive.__salt__, {'cmd.run': mock}):
                    ret = archive.unrar(
                        '/tmp/rarfile.rar',
                        '/home/strongbad/',
                        excludes='file_1,file_2'
                    )
                    self.assertEqual(['salt'], ret)
                    mock.assert_called_once_with(
                        ['unrar', 'x', '-idp', '/tmp/rarfile.rar',
                         '-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
                        runas=None, python_shell=False, template=None
                    )

                mock = MagicMock(return_value='salt')
                with patch.dict(archive.__salt__, {'cmd.run': mock}):
                    ret = archive.unrar(
                        '/tmp/rarfile.rar',
                        '/home/strongbad/',
                        excludes=['file_1', 'file_2']
                    )
                    self.assertEqual(['salt'], ret)
                    mock.assert_called_once_with(
                        ['unrar', 'x', '-idp', '/tmp/rarfile.rar',
                         '-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
                        runas=None, python_shell=False, template=None
                    )
Beispiel #4
0
    def test_unrar(self):
        with patch(
                "salt.utils.path.which_bin",
                lambda exe: exe[0] if isinstance(exe, (list, tuple)) else exe,
        ):
            with patch(
                    "salt.utils.path.which",
                    lambda exe: exe[0]
                    if isinstance(exe, (list, tuple)) else exe,
            ):
                mock = MagicMock(return_value="salt")
                with patch.dict(archive.__salt__, {"cmd.run": mock}):
                    ret = archive.unrar("/tmp/rarfile.rar",
                                        "/home/strongbad/",
                                        excludes="file_1,file_2")
                    self.assertEqual(["salt"], ret)
                    mock.assert_called_once_with(
                        [
                            "unrar",
                            "x",
                            "-idp",
                            "/tmp/rarfile.rar",
                            "-x",
                            "file_1",
                            "-x",
                            "file_2",
                            "/home/strongbad/",
                        ],
                        runas=None,
                        python_shell=False,
                        template=None,
                    )

                mock = MagicMock(return_value="salt")
                with patch.dict(archive.__salt__, {"cmd.run": mock}):
                    ret = archive.unrar(
                        "/tmp/rarfile.rar",
                        "/home/strongbad/",
                        excludes=["file_1", "file_2"],
                    )
                    self.assertEqual(["salt"], ret)
                    mock.assert_called_once_with(
                        [
                            "unrar",
                            "x",
                            "-idp",
                            "/tmp/rarfile.rar",
                            "-x",
                            "file_1",
                            "-x",
                            "file_2",
                            "/home/strongbad/",
                        ],
                        runas=None,
                        python_shell=False,
                        template=None,
                    )
Beispiel #5
0
def test_unrar_raises_exception_if_not_found():
    with patch("salt.utils.path.which_bin", lambda exe: None):
        mock = MagicMock(return_value="salt")
        with patch.dict(archive.__salt__, {"cmd.run": mock}):
            with pytest.raises(CommandNotFoundError):
                archive.unrar(
                    "/tmp/rarfile.rar", "/home/strongbad/",
                )
            assert not mock.called
Beispiel #6
0
    def test_trim_files(self):
        source = 'file.tar.gz'
        tmp_dir = 'temp'
        files = [
            '\n'.join(['file1'] * 200),
            '\n'.join(['file2'] * 200),
            'this\nthat\nother',
            'this\nthat\nother',
            'this\nthat\nother'
        ]
        trim_opt = [
            True,
            False,
            3,
            1,
            0
        ]
        trim_100 = (['file1'] * 100)
        trim_100.append("List trimmed after 100 files.")
        expected = [
            trim_100,
            ['file2'] * 200,
            ['this', 'that', 'other'],
            ['this', 'List trimmed after 1 files.'],
            ['List trimmed after 0 files.'],
        ]

        for test_files, test_trim_opts, test_expected in zip(files, trim_opt, expected):
            with patch.dict(archive.__salt__, {'cmd.run': MagicMock(return_value=test_files)}):
                ret = archive.unrar(source, tmp_dir, trim_output=test_trim_opts)
                self.assertEqual(ret, test_expected)
Beispiel #7
0
def test_trim_files():
    with patch("salt.utils.path.which_bin", lambda exe: exe):
        source = "file.tar.gz"
        tmp_dir = "temp"
        files = [
            "\n".join(["file1"] * 200),
            "\n".join(["file2"] * 200),
            "this\nthat\nother",
            "this\nthat\nother",
            "this\nthat\nother",
        ]
        trim_opt = [True, False, 3, 1, 0]
        trim_100 = ["file1"] * 100
        trim_100.append("List trimmed after 100 files.")
        expected = [
            trim_100,
            ["file2"] * 200,
            ["this", "that", "other"],
            ["this", "List trimmed after 1 files."],
            ["List trimmed after 0 files."],
        ]

        for test_files, test_trim_opts, test_expected in zip(
                files, trim_opt, expected):
            with patch.dict(archive.__salt__,
                            {"cmd.run": MagicMock(return_value=test_files)}):
                ret = archive.unrar(source,
                                    tmp_dir,
                                    trim_output=test_trim_opts)
                assert ret == test_expected
Beispiel #8
0
    def test_trim_files(self):
        source = 'file.tar.gz'
        tmp_dir = 'temp'
        files = [
            '\n'.join(['file1'] * 200),
            '\n'.join(['file2'] * 200),
            'this\nthat\nother',
            'this\nthat\nother',
            'this\nthat\nother'
        ]
        trim_opt = [
            True,
            False,
            3,
            1,
            0
        ]
        trim_100 = (['file1'] * 100)
        trim_100.append("List trimmed after 100 files.")
        expected = [
            trim_100,
            ['file2'] * 200,
            ['this', 'that', 'other'],
            ['this', 'List trimmed after 1 files.'],
            ['List trimmed after 0 files.'],
        ]

        for test_files, test_trim_opts, test_expected in zip(files, trim_opt, expected):
            with patch.dict(archive.__salt__, {'cmd.run': MagicMock(return_value=test_files)}):
                ret = archive.unrar(source, tmp_dir, trim_output=test_trim_opts)
                self.assertEqual(ret, test_expected)
Beispiel #9
0
def test_unrar(unicode_filename):
    """
    Validate using the unrar function
    """
    with Archive("rar", unicode_filename=unicode_filename) as arch:
        ret = archive.rar(str(arch.archive), str(arch.src))
        assert isinstance(ret, list)
        arch.assert_artifacts_in_ret(ret)

        ret = archive.unrar(str(arch.archive), str(arch.dst))
        assert isinstance(ret, list)
        arch.assert_artifacts_in_ret(ret)