Add unit tests for pkgng.lock and pkgng.unlock

This commit is contained in:
Adam Mendlik 2017-12-27 09:49:12 -07:00
parent f27fe6bbe9
commit 292db68c44
No known key found for this signature in database
GPG Key ID: BD2747BB4A930106

View 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
)