salt/tests/unit/modules/test_znc.py
2017-03-01 01:33:07 +00:00

77 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
from salt.modules import znc
znc.__salt__ = {}
@skipIf(NO_MOCK, NO_MOCK_REASON)
class ZncTestCase(TestCase):
'''
TestCase for salt.modules.znc
'''
# 'buildmod' function tests: 1
@patch('os.path.exists', MagicMock(return_value=False))
def test_buildmod(self):
'''
Tests build module using znc-buildmod
'''
self.assertEqual(znc.buildmod('modules.cpp'),
'Error: The file (modules.cpp) does not exist.')
@patch('os.path.exists', MagicMock(return_value=True))
def test_buildmod_module(self):
'''
Tests build module using znc-buildmod
'''
mock = MagicMock(return_value='SALT')
with patch.dict(znc.__salt__, {'cmd.run': mock}):
self.assertEqual(znc.buildmod('modules.cpp'), 'SALT')
# 'dumpconf' function tests: 1
def test_dumpconf(self):
'''
Tests write the active configuration state to config file
'''
mock = MagicMock(return_value='SALT')
with patch.dict(znc.__salt__, {'ps.pkill': mock}):
self.assertEqual(znc.dumpconf(), 'SALT')
# 'rehashconf' function tests: 1
def test_rehashconf(self):
'''
Tests rehash the active configuration state from config file
'''
mock = MagicMock(return_value='SALT')
with patch.dict(znc.__salt__, {'ps.pkill': mock}):
self.assertEqual(znc.rehashconf(), 'SALT')
# 'version' function tests: 1
def test_version(self):
'''
Tests return server version from znc --version
'''
mock = MagicMock(return_value='ZNC 1.2 - http://znc.in')
with patch.dict(znc.__salt__, {'cmd.run': mock}):
self.assertEqual(znc.version(), 'ZNC 1.2')