salt/tests/unit/states/test_apt.py

45 lines
1.1 KiB
Python
Raw Normal View History

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-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
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)
# Import Salt Libs
import salt.states.aptpkg as aptpkg
2015-04-20 10:27:54 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class AptTestCase(TestCase, LoaderModuleMockMixin):
2015-04-20 10:27:54 +00:00
'''
Test cases for salt.states.aptpkg
2015-04-20 10:27:54 +00:00
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {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)
with patch.dict(aptpkg.__salt__, {'pkg.get_selections': mock}):
self.assertDictEqual(aptpkg.held(name), ret)