def test_file_dict(self):
        """
        Test if it lists the files that belong to a package, grouped by package
        """
        dpkg_query_mock = MagicMock(return_value={
            "retcode": 0,
            "stderr": "",
            "stdout": "installed\thostname"
        })
        dpkg_L_mock = MagicMock(side_effect=self.dpkg_L_side_effect)
        with patch.dict(dpkg.__salt__, {
                "cmd.run_all": dpkg_query_mock,
                "cmd.run": dpkg_L_mock
        }):
            expected = {
                "errors": [],
                "packages": {
                    "hostname": [
                        "/.",
                        "/bin",
                        "/bin/hostname",
                        "/usr",
                        "/usr/share",
                        "/usr/share/doc",
                        "/usr/share/doc/hostname",
                        "/usr/share/doc/hostname/changelog.gz",
                        "/usr/share/doc/hostname/copyright",
                        "/usr/share/man",
                        "/usr/share/man/man1",
                        "/usr/share/man/man1/hostname.1.gz",
                        "/bin/dnsdomainname",
                        "/bin/domainname",
                        "/bin/nisdomainname",
                        "/bin/ypdomainname",
                        "/usr/share/man/man1/dnsdomainname.1.gz",
                        "/usr/share/man/man1/domainname.1.gz",
                        "/usr/share/man/man1/nisdomainname.1.gz",
                        "/usr/share/man/man1/ypdomainname.1.gz",
                    ]
                },
            }
            self.assertDictEqual(dpkg.file_dict("hostname"), expected)

        mock = MagicMock(return_value={
            "retcode": 1,
            "stderr": DPKG_ERROR_MSG,
            "stdout": ""
        })
        with patch.dict(dpkg.__salt__, {"cmd.run_all": mock}):
            self.assertEqual(dpkg.file_dict("httpd"),
                             "Error:  " + DPKG_ERROR_MSG)
Example #2
0
    def test_file_dict(self):
        '''
        Test if it lists the files that belong to a package, grouped by package
        '''
        mock = MagicMock(return_value={'retcode': 0,
                                       'stderr': '',
                                       'stdout': 'Salt'})
        with patch.dict(dpkg.__salt__, {'cmd.run_all': mock}):
            self.assertDictEqual(dpkg.file_dict('httpd'),
                                 {'errors': [], 'packages': {}})

        mock = MagicMock(return_value={'retcode': 1,
                                       'stderr': 'error',
                                       'stdout': 'Salt'})
        with patch.dict(dpkg.__salt__, {'cmd.run_all': mock}):
            self.assertEqual(dpkg.file_dict('httpd'), 'Error:  error')
Example #3
0
    def test_file_dict(self):
        """
        Test if it lists the files that belong to a package, grouped by package
        """
        mock = MagicMock(return_value={
            "retcode": 0,
            "stderr": "",
            "stdout": "Salt"
        })
        with patch.dict(dpkg.__salt__, {"cmd.run_all": mock}):
            self.assertDictEqual(dpkg.file_dict("httpd"), {
                "errors": [],
                "packages": {}
            })

        mock = MagicMock(return_value={
            "retcode": 1,
            "stderr": "error",
            "stdout": "Salt"
        })
        with patch.dict(dpkg.__salt__, {"cmd.run_all": mock}):
            self.assertEqual(dpkg.file_dict("httpd"), "Error:  error")