Пример #1
0
 def test_checksum_root(self):
     '''
     Test if checksum validate as expected, using the parameter
     root
     '''
     mock = MagicMock(side_effect=[True, 0])
     with patch.dict(rpm.__salt__, {'file.file_exists': mock, 'cmd.retcode': mock}):
         rpm.checksum("file1.rpm", root='/')
         self.assertTrue(_called_with_root(mock))
Пример #2
0
def test_checksum_root():
    """
    Test if checksum validate as expected, using the parameter
    root
    """
    mock = MagicMock(side_effect=[True, 0])
    with patch.dict(rpm.__salt__, {
            "file.file_exists": mock,
            "cmd.retcode": mock
    }):
        rpm.checksum("file1.rpm", root="/")
        assert _called_with_root(mock)
Пример #3
0
    def test_checksum(self):
        '''
        Test if checksum validate as expected
        '''
        ret = {
            "file1.rpm": True,
            "file2.rpm": False,
            "file3.rpm": False,
        }

        mock = MagicMock(side_effect=[True, 0, True, 1, False, 0])
        with patch.dict(rpm.__salt__, {'file.file_exists': mock, 'cmd.retcode': mock}):
            self.assertDictEqual(rpm.checksum("file1.rpm", "file2.rpm", "file3.rpm"), ret)
Пример #4
0
    def test_checksum(self):
        """
        Test if checksum validate as expected
        """
        ret = {
            "file1.rpm": True,
            "file2.rpm": False,
            "file3.rpm": False,
        }

        mock = MagicMock(side_effect=[True, 0, True, 1, False, 0])
        with patch.dict(rpm.__salt__, {"file.file_exists": mock, "cmd.retcode": mock}):
            self.assertDictEqual(
                rpm.checksum("file1.rpm", "file2.rpm", "file3.rpm"), ret
            )
            self.assertFalse(_called_with_root(mock))
Пример #5
0
    def test_file_list(self):
        """
        Test if it list the files that belong to a package.
        '''
        mock = MagicMock(return_value='')
        with patch.dict(rpm.__salt__, {'cmd.run': mock}):
            self.assertDictEqual(rpm.file_list('httpd'),
                                 {'errors': [], 'files': []})
            self.assertFalse(_called_with_root(mock))

    def test_file_list_root(self):
        '''
        Test if it list the files that belong to a package, using the
        root parameter.
        '''

        mock = MagicMock(return_value='')
        with patch.dict(rpm.__salt__, {'cmd.run': mock}):
            rpm.file_list('httpd', root='/')
            self.assertTrue(_called_with_root(mock))

    # 'file_dict' function tests: 2

    def test_file_dict(self):
        """
        Test if it list the files that belong to a package
        '''
        mock = MagicMock(return_value='')
        with patch.dict(rpm.__salt__, {'cmd.run': mock}):
            self.assertDictEqual(rpm.file_dict('httpd'),
                                 {'errors': [], 'packages': {}})
            self.assertFalse(_called_with_root(mock))

    def test_file_dict_root(self):
        '''
        Test if it list the files that belong to a package
        '''
        mock = MagicMock(return_value='')
        with patch.dict(rpm.__salt__, {'cmd.run': mock}):
            rpm.file_dict('httpd', root='/')
            self.assertTrue(_called_with_root(mock))

    # 'owner' function tests: 1

    def test_owner(self):
        """
        Test if it return the name of the package that owns the file.
        """
        self.assertEqual(rpm.owner(), "")

        ret = "file /usr/bin/salt-jenkins-build is not owned by any package"
        mock = MagicMock(return_value=ret)
        with patch.dict(rpm.__salt__, {'cmd.run_stdout': mock}):
            self.assertEqual(rpm.owner('/usr/bin/salt-jenkins-build'), '')
            self.assertFalse(_called_with_root(mock))

        ret = {'/usr/bin/vim': 'vim-enhanced-7.4.160-1.e17.x86_64',
               '/usr/bin/python': 'python-2.7.5-16.e17.x86_64'}
        mock = MagicMock(side_effect=['python-2.7.5-16.e17.x86_64',
                                      'vim-enhanced-7.4.160-1.e17.x86_64'])
        with patch.dict(rpm.__salt__, {'cmd.run_stdout': mock}):
            self.assertDictEqual(rpm.owner('/usr/bin/python', '/usr/bin/vim'),
                                 ret)
            self.assertFalse(_called_with_root(mock))

    def test_owner_root(self):
        '''
        Test if it return the name of the package that owns the file,
        using the parameter root.
        '''
        self.assertEqual(rpm.owner(), '')

        ret = 'file /usr/bin/salt-jenkins-build is not owned by any package'
        mock = MagicMock(return_value=ret)
        with patch.dict(rpm.__salt__, {'cmd.run_stdout': mock}):
            rpm.owner('/usr/bin/salt-jenkins-build', root='/')
            self.assertTrue(_called_with_root(mock))

    # 'checksum' function tests: 2

    def test_checksum(self):
        """
        Test if checksum validate as expected
        """
        ret = {
            "file1.rpm": True,
            "file2.rpm": False,
            "file3.rpm": False,
        }

        mock = MagicMock(side_effect=[True, 0, True, 1, False, 0])
        with patch.dict(rpm.__salt__, {'file.file_exists': mock, 'cmd.retcode': mock}):
            self.assertDictEqual(rpm.checksum("file1.rpm", "file2.rpm", "file3.rpm"), ret)
            self.assertFalse(_called_with_root(mock))

    def test_checksum_root(self):
        '''
        Test if checksum validate as expected, using the parameter
        root
        '''
        mock = MagicMock(side_effect=[True, 0])
        with patch.dict(rpm.__salt__, {'file.file_exists': mock, 'cmd.retcode': mock}):
            rpm.checksum("file1.rpm", root='/')
            self.assertTrue(_called_with_root(mock))