mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Add unit tests for pkgng.lock and pkgng.unlock
This commit is contained in:
parent
f27fe6bbe9
commit
292db68c44
103
tests/unit/modules/test_pkgng.py
Normal file
103
tests/unit/modules/test_pkgng.py
Normal file
@ -0,0 +1,103 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
from tests.support.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
MagicMock,
|
||||
patch)
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.modules.pkgng as pkgng
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class PkgNgTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
Test cases for salt.modules.pkgng
|
||||
'''
|
||||
|
||||
@classmethod
|
||||
def setup_loader_modules(cls):
|
||||
return {
|
||||
pkgng: {
|
||||
'__salt__': {}
|
||||
}
|
||||
}
|
||||
|
||||
def test_lock(self):
|
||||
'''
|
||||
Test pkgng.lock
|
||||
'''
|
||||
lock_cmd = MagicMock(return_value={
|
||||
'stdout': 'pkga-1.0\npkgb-2.0\n',
|
||||
'retcode': 0
|
||||
})
|
||||
with patch.dict(pkgng.__salt__, {'cmd.run_all': lock_cmd}):
|
||||
|
||||
result = pkgng.lock('pkga')
|
||||
self.assertTrue(result)
|
||||
lock_cmd.assert_called_with(
|
||||
['pkg', 'lock', '-y', '--quiet', '--show-locked', 'pkga'],
|
||||
output_loglevel='trace', python_shell=False
|
||||
)
|
||||
|
||||
result = pkgng.lock('dummy')
|
||||
self.assertFalse(result)
|
||||
lock_cmd.assert_called_with(
|
||||
['pkg', 'lock', '-y', '--quiet', '--show-locked', 'dummy'],
|
||||
output_loglevel='trace', python_shell=False
|
||||
)
|
||||
|
||||
def test_unlock(self):
|
||||
'''
|
||||
Test pkgng.unlock
|
||||
'''
|
||||
unlock_cmd = MagicMock(return_value={
|
||||
'stdout': 'pkga-1.0\npkgb-2.0\n',
|
||||
'retcode': 0
|
||||
})
|
||||
with patch.dict(pkgng.__salt__, {'cmd.run_all': unlock_cmd}):
|
||||
|
||||
result = pkgng.unlock('pkga')
|
||||
self.assertFalse(result)
|
||||
unlock_cmd.assert_called_with(
|
||||
['pkg', 'unlock', '-y', '--quiet', '--show-locked', 'pkga'],
|
||||
output_loglevel='trace', python_shell=False
|
||||
)
|
||||
|
||||
result = pkgng.unlock('dummy')
|
||||
self.assertTrue(result)
|
||||
unlock_cmd.assert_called_with(
|
||||
['pkg', 'unlock', '-y', '--quiet', '--show-locked', 'dummy'],
|
||||
output_loglevel='trace', python_shell=False
|
||||
)
|
||||
|
||||
def test_locked(self):
|
||||
'''
|
||||
Test pkgng.unlock
|
||||
'''
|
||||
lock_cmd = MagicMock(return_value={
|
||||
'stdout': 'pkga-1.0\npkgb-2.0\n',
|
||||
'retcode': 0
|
||||
})
|
||||
with patch.dict(pkgng.__salt__, {'cmd.run_all': lock_cmd}):
|
||||
|
||||
result = pkgng.locked('pkga')
|
||||
self.assertTrue(result)
|
||||
lock_cmd.assert_called_with(
|
||||
['pkg', 'lock', '-y', '--quiet', '--show-locked'],
|
||||
output_loglevel='trace', python_shell=False
|
||||
)
|
||||
|
||||
result = pkgng.locked('dummy')
|
||||
self.assertFalse(result)
|
||||
lock_cmd.assert_called_with(
|
||||
['pkg', 'lock', '-y', '--quiet', '--show-locked'],
|
||||
output_loglevel='trace', python_shell=False
|
||||
)
|
Loading…
Reference in New Issue
Block a user