Beispiel #1
0
    def test_latest_version(self):
        """
        Test getting the latest version of a package
        """

        # Test getting the latest version of an uninstalled package
        pkgin_out = [
            "somepkg-1.0;;Some package description here",
            "",
            "=: package is installed and up-to-date",
            "<: package is installed but newer version is available",
            ">: installed package has a greater version than available package",
        ]

        pkgin__get_version_mock = MagicMock(return_value=["0", "9", "0"])
        pkgin__check_pkgin_mock = MagicMock(return_value="/opt/pkg/bin/pkgin")
        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))

        with patch("salt.modules.pkgin.refresh_db",
                   pkgin_refresh_db_mock), patch(
                       "salt.modules.pkgin._get_version",
                       pkgin__get_version_mock), patch(
                           "salt.modules.pkgin._check_pkgin",
                           pkgin__check_pkgin_mock), patch.dict(
                               pkgin.__salt__, {"cmd.run": pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version("somepkg"), "1.0")

        # Test getting the latest version of an installed package
        pkgin_out = [
            "somepkg-1.1;<;Some package description here",
            "",
            "=: package is installed and up-to-date",
            "<: package is installed but newer version is available",
            ">: installed package has a greater version than available package",
        ]

        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))

        with patch("salt.modules.pkgin.refresh_db",
                   pkgin_refresh_db_mock), patch(
                       "salt.modules.pkgin._get_version",
                       pkgin__get_version_mock), patch(
                           "salt.modules.pkgin._check_pkgin",
                           pkgin__check_pkgin_mock), patch.dict(
                               pkgin.__salt__, {"cmd.run": pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version("somepkg"), "1.1")

        # Test getting the latest version of a package that is already installed
        # and is already at the latest version
        pkgin_out = [
            "somepkg-1.2;=;Some package description here",
            "",
            "=: package is installed and up-to-date",
            "<: package is installed but newer version is available",
            ">: installed package has a greater version than available package",
        ]

        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))

        with patch("salt.modules.pkgin.refresh_db",
                   pkgin_refresh_db_mock), patch(
                       "salt.modules.pkgin._get_version",
                       pkgin__get_version_mock), patch(
                           "salt.modules.pkgin._check_pkgin",
                           pkgin__check_pkgin_mock), patch.dict(
                               pkgin.__salt__, {"cmd.run": pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version("somepkg"), "1.2")

        # Test getting the latest version of a bogus package
        pkgin_out = "No results found for ^boguspkg$"

        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=pkgin_out)

        with patch("salt.modules.pkgin.refresh_db",
                   pkgin_refresh_db_mock), patch(
                       "salt.modules.pkgin._get_version",
                       pkgin__get_version_mock), patch(
                           "salt.modules.pkgin._check_pkgin",
                           pkgin__check_pkgin_mock), patch.dict(
                               pkgin.__salt__, {"cmd.run": pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version("boguspkg"), {})
Beispiel #2
0
    def test_latest_version(self):
        '''
        Test getting the latest version of a package
        '''

        # Test getting the latest version of an uninstalled package
        pkgin_out = [
            'somepkg-1.0;;Some package description here', '',
            '=: package is installed and up-to-date',
            '<: package is installed but newer version is available',
            '>: installed package has a greater version than available package'
        ]

        pkgin__get_version_mock = MagicMock(return_value=['0', '9', '0'])
        pkgin__check_pkgin_mock = MagicMock(return_value='/opt/pkg/bin/pkgin')
        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))

        with patch('salt.modules.pkgin.refresh_db', pkgin_refresh_db_mock), \
             patch('salt.modules.pkgin._get_version', pkgin__get_version_mock), \
             patch('salt.modules.pkgin._check_pkgin', pkgin__check_pkgin_mock), \
             patch.dict(pkgin.__salt__, {'cmd.run': pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version('somepkg'), '1.0')

        # Test getting the latest version of an installed package
        pkgin_out = [
            'somepkg-1.1;<;Some package description here', '',
            '=: package is installed and up-to-date',
            '<: package is installed but newer version is available',
            '>: installed package has a greater version than available package'
        ]

        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))

        with patch('salt.modules.pkgin.refresh_db', pkgin_refresh_db_mock), \
             patch('salt.modules.pkgin._get_version', pkgin__get_version_mock), \
             patch('salt.modules.pkgin._check_pkgin', pkgin__check_pkgin_mock), \
             patch.dict(pkgin.__salt__, {'cmd.run': pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version('somepkg'), '1.1')

        # Test getting the latest version of a package that is already installed
        # and is already at the latest version
        pkgin_out = [
            'somepkg-1.2;=;Some package description here', '',
            '=: package is installed and up-to-date',
            '<: package is installed but newer version is available',
            '>: installed package has a greater version than available package'
        ]

        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))

        with patch('salt.modules.pkgin.refresh_db', pkgin_refresh_db_mock), \
             patch('salt.modules.pkgin._get_version', pkgin__get_version_mock), \
             patch('salt.modules.pkgin._check_pkgin', pkgin__check_pkgin_mock), \
             patch.dict(pkgin.__salt__, {'cmd.run': pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version('somepkg'), '1.2')

        # Test getting the latest version of a bogus package
        pkgin_out = 'No results found for ^boguspkg$'

        pkgin_refresh_db_mock = MagicMock(return_value=True)
        pkgin_search_cmd = MagicMock(return_value=pkgin_out)

        with patch('salt.modules.pkgin.refresh_db', pkgin_refresh_db_mock), \
             patch('salt.modules.pkgin._get_version', pkgin__get_version_mock), \
             patch('salt.modules.pkgin._check_pkgin', pkgin__check_pkgin_mock), \
             patch.dict(pkgin.__salt__, {'cmd.run': pkgin_search_cmd}):
            self.assertEqual(pkgin.latest_version('boguspkg'), {})