salt/tests/unit/modules/win_repo_test.py

69 lines
2.1 KiB
Python
Raw Normal View History

2015-04-08 08:37:03 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
import os
# Import Salt Testing Libs
import salt.output
from salttesting import TestCase, skipIf
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import (
mock_open,
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
ensure_in_syspath('../../')
# Import Salt Libs
from salt.modules import win_repo
win_repo.__opts__ = {}
win_repo.__salt__ = {}
2015-04-08 08:37:03 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
class WinRepoTestCase(TestCase):
'''
Test cases for salt.modules.win_repo
'''
@patch('salt.loader.render', MagicMock(return_valu=''))
2015-04-08 08:37:03 +00:00
def test_genrepo(self):
'''
Test to generate winrepo_cachefile based on sls files in the
winrepo_dir
2015-04-08 08:37:03 +00:00
'''
with patch.dict(win_repo.__opts__, {'winrepo_dir': 'c:\\salt'}):
2015-04-08 08:37:03 +00:00
mock_bool = MagicMock(return_value=True)
with patch.object(os.path, 'exists', mock_bool):
with patch.dict(win_repo.__opts__,
{'winrepo_cachefile': 'cache.c'}):
2015-04-08 08:37:03 +00:00
mock = MagicMock(return_value={})
with patch.object(os, 'walk', mock):
with patch('salt.utils.fopen', mock_open()):
with patch.object(salt.output, 'display_output',
mock_bool):
self.assertDictEqual(win_repo.genrepo(), {})
def test_update_git_repos(self):
'''
Test to checkout git repos containing Windows software package
definitions
2015-04-08 08:37:03 +00:00
'''
with patch.dict(win_repo.__opts__, {'winrepo_dir': 'c:\\salt'}):
with patch.dict(win_repo.__opts__, {'winrepo_remotes': {}}):
2015-04-08 08:37:03 +00:00
mock = MagicMock(return_value=True)
with patch.object(salt.output, 'display_output', mock):
self.assertDictEqual(win_repo.update_git_repos(), {})
if __name__ == '__main__':
from integration import run_tests
run_tests(WinRepoTestCase, needs_daemon=False)