2015-04-20 10:27:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
|
|
|
'''
|
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf, TestCase
|
|
|
|
from tests.support.mock import (
|
2015-04-20 10:27:54 +00:00
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON,
|
|
|
|
MagicMock,
|
|
|
|
patch)
|
|
|
|
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.helpers import ensure_in_syspath
|
2015-04-20 10:27:54 +00:00
|
|
|
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2015-06-04 11:22:06 +00:00
|
|
|
from salt.states import aptpkg
|
2015-04-20 10:27:54 +00:00
|
|
|
|
2015-06-04 11:22:06 +00:00
|
|
|
aptpkg.__opts__ = {}
|
|
|
|
aptpkg.__salt__ = {}
|
2015-04-20 10:27:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
|
|
|
class AptTestCase(TestCase):
|
|
|
|
'''
|
2015-06-04 11:22:06 +00:00
|
|
|
Test cases for salt.states.aptpkg
|
2015-04-20 10:27:54 +00:00
|
|
|
'''
|
|
|
|
# 'held' function tests: 1
|
|
|
|
|
|
|
|
def test_held(self):
|
|
|
|
'''
|
|
|
|
Test to set package in 'hold' state, meaning it will not be upgraded.
|
|
|
|
'''
|
|
|
|
name = 'tmux'
|
|
|
|
|
|
|
|
ret = {'name': name,
|
|
|
|
'result': False,
|
|
|
|
'changes': {},
|
|
|
|
'comment': 'Package {0} does not have a state'.format(name)}
|
|
|
|
|
|
|
|
mock = MagicMock(return_value=False)
|
2015-06-04 11:22:06 +00:00
|
|
|
with patch.dict(aptpkg.__salt__, {'pkg.get_selections': mock}):
|
|
|
|
self.assertDictEqual(aptpkg.held(name), ret)
|
2015-04-20 10:27:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(AptTestCase, needs_daemon=False)
|