2016-07-13 03:46:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Anthony Shaw <anthonyshaw@apache.org>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python Libs
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2016-07-13 03:46:04 +00:00
|
|
|
from tests.unit import ModuleTestCase, hasDependency
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.mock import (
|
2016-07-13 03:46:04 +00:00
|
|
|
patch,
|
|
|
|
MagicMock,
|
|
|
|
NO_MOCK,
|
|
|
|
NO_MOCK_REASON
|
|
|
|
)
|
2017-03-21 17:15:36 +00:00
|
|
|
import salt.modules.libcloud_dns as libcloud_dns
|
2016-07-13 03:46:04 +00:00
|
|
|
|
|
|
|
SERVICE_NAME = 'libcloud_dns'
|
|
|
|
libcloud_dns.__salt__ = {}
|
2016-07-13 15:47:20 +00:00
|
|
|
libcloud_dns.__utils__ = {}
|
2016-07-13 03:46:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MockDNSDriver(object):
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def get_mock_driver():
|
|
|
|
return MockDNSDriver()
|
|
|
|
|
|
|
|
|
|
|
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
|
|
|
@patch('salt.modules.libcloud_dns._get_driver',
|
|
|
|
MagicMock(return_value=MockDNSDriver()))
|
|
|
|
class LibcloudDnsModuleTestCase(ModuleTestCase):
|
|
|
|
def setUp(self):
|
2016-12-05 23:55:18 +00:00
|
|
|
hasDependency('libcloud', fake_module=False)
|
2016-07-13 03:46:04 +00:00
|
|
|
|
|
|
|
def get_config(service):
|
|
|
|
if service == SERVICE_NAME:
|
|
|
|
return {
|
|
|
|
'test': {
|
|
|
|
'driver': 'test',
|
|
|
|
'key': '2orgk34kgk34g'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
raise KeyError("service name invalid")
|
|
|
|
|
|
|
|
self.setup_loader()
|
|
|
|
self.loader.set_result(libcloud_dns, 'config.option', get_config)
|
|
|
|
|
|
|
|
def test_module_creation(self, *args):
|
|
|
|
client = libcloud_dns._get_driver('test')
|
|
|
|
self.assertFalse(client is None)
|
|
|
|
|
2016-07-13 15:47:20 +00:00
|
|
|
def test_init(self):
|
|
|
|
with patch('salt.utils.compat.pack_dunder', return_value=False) as dunder:
|
|
|
|
libcloud_dns.__init__(None)
|
|
|
|
dunder.assert_called_with('salt.modules.libcloud_dns')
|