Exemple #1
0
    def test_latest_installed_at_latest(self):
        '''
        Test - latest_installed when no upgrade is available
        '''
        installed = MagicMock(return_value=KERNEL_LIST)
        upgrade = MagicMock(return_value=KERNEL_LIST[-1])
        with patch.dict(kernelpkg.__salt__,
                        {'kernelpkg.list_installed': installed}):
            with patch.dict(kernelpkg.__salt__,
                            {'kernelpkg.latest_available': upgrade}):
                with patch.dict(kernelpkg.__opts__, {'test': False}):
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret['name'], STATE_NAME)
                    self.assertTrue(ret['result'])
                    self.assertDictEqual(ret['changes'], {})
                    self.assertIsInstance(ret['comment'], six.text_type)
                    kernelpkg.__salt__['kernelpkg.upgrade'].assert_not_called()

                with patch.dict(kernelpkg.__opts__, {'test': True}):
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret['name'], STATE_NAME)
                    self.assertTrue(ret['result'])
                    self.assertDictEqual(ret['changes'], {})
                    self.assertIsInstance(ret['comment'], six.text_type)
                    kernelpkg.__salt__['kernelpkg.upgrade'].assert_not_called()
Exemple #2
0
    def test_latest_installed_with_changes(self):
        '''
        Test - latest_installed when an upgrade is available
        '''
        installed = MagicMock(return_value=KERNEL_LIST[:-1])
        upgrade = MagicMock(return_value=KERNEL_LIST[-1])
        with patch.dict(kernelpkg.__salt__,
                        {'kernelpkg.list_installed': installed}):
            with patch.dict(kernelpkg.__salt__,
                            {'kernelpkg.latest_available': upgrade}):
                with patch.dict(kernelpkg.__opts__, {'test': False}):
                    kernelpkg.__salt__['kernelpkg.upgrade'].reset_mock()
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret['name'], STATE_NAME)
                    self.assertTrue(ret['result'])
                    self.assertIsInstance(ret['changes'], dict)
                    self.assertIsInstance(ret['comment'], str)
                    self.assert_called_once(
                        kernelpkg.__salt__['kernelpkg.upgrade'])

                with patch.dict(kernelpkg.__opts__, {'test': True}):
                    kernelpkg.__salt__['kernelpkg.upgrade'].reset_mock()
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret['name'], STATE_NAME)
                    self.assertIsNone(ret['result'])
                    self.assertDictEqual(ret['changes'], {})
                    self.assertIsInstance(ret['comment'], str)
                    kernelpkg.__salt__['kernelpkg.upgrade'].assert_not_called()
    def test_latest_installed_at_latest(self):
        """
        Test - latest_installed when no upgrade is available
        """
        installed = MagicMock(return_value=KERNEL_LIST)
        upgrade = MagicMock(return_value=KERNEL_LIST[-1])
        with patch.dict(kernelpkg.__salt__,
                        {"kernelpkg.list_installed": installed}):
            with patch.dict(kernelpkg.__salt__,
                            {"kernelpkg.latest_available": upgrade}):
                with patch.dict(kernelpkg.__opts__, {"test": False}):
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret["name"], STATE_NAME)
                    self.assertTrue(ret["result"])
                    self.assertDictEqual(ret["changes"], {})
                    self.assertIsInstance(ret["comment"], six.text_type)
                    kernelpkg.__salt__["kernelpkg.upgrade"].assert_not_called()

                with patch.dict(kernelpkg.__opts__, {"test": True}):
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret["name"], STATE_NAME)
                    self.assertTrue(ret["result"])
                    self.assertDictEqual(ret["changes"], {})
                    self.assertIsInstance(ret["comment"], six.text_type)
                    kernelpkg.__salt__["kernelpkg.upgrade"].assert_not_called()
Exemple #4
0
    def test_latest_installed_with_changes(self):
        """
        Test - latest_installed when an upgrade is available
        """
        installed = MagicMock(return_value=KERNEL_LIST[:-1])
        upgrade = MagicMock(return_value=KERNEL_LIST[-1])
        with patch.dict(kernelpkg.__salt__,
                        {"kernelpkg.list_installed": installed}):
            with patch.dict(kernelpkg.__salt__,
                            {"kernelpkg.latest_available": upgrade}):
                with patch.dict(kernelpkg.__opts__, {"test": False}):
                    kernelpkg.__salt__["kernelpkg.upgrade"].reset_mock()
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret["name"], STATE_NAME)
                    self.assertTrue(ret["result"])
                    self.assertIsInstance(ret["changes"], dict)
                    self.assertIsInstance(ret["comment"], str)
                    self.assert_called_once(
                        kernelpkg.__salt__["kernelpkg.upgrade"])

                with patch.dict(kernelpkg.__opts__, {"test": True}):
                    kernelpkg.__salt__["kernelpkg.upgrade"].reset_mock()
                    ret = kernelpkg.latest_installed(name=STATE_NAME)
                    self.assertEqual(ret["name"], STATE_NAME)
                    self.assertIsNone(ret["result"])
                    self.assertDictEqual(ret["changes"], {})
                    self.assertIsInstance(ret["comment"], str)
                    kernelpkg.__salt__["kernelpkg.upgrade"].assert_not_called()