salt/tests/unit/modules/test_saltcloudmod.py

69 lines
1.7 KiB
Python
Raw Normal View History

2015-03-31 10:02:49 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
2017-02-19 15:35:30 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
2015-03-31 10:02:49 +00:00
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
2017-02-19 15:35:30 +00:00
import salt.modules.saltcloudmod as saltcloudmod
2015-03-31 10:02:49 +00:00
class MockJson(object):
'''
Mock json class
'''
flag = None
def __init__(self):
pass
@staticmethod
def loads(data, object_hook):
'''
Mock load method
'''
if MockJson.flag:
return data, object_hook
else:
raise ValueError
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-02-19 15:35:30 +00:00
class SaltcloudmodTestCase(TestCase, LoaderModuleMockMixin):
2015-03-31 10:02:49 +00:00
'''
Test cases for salt.modules.saltcloudmod
'''
def setup_loader_modules(self):
return {saltcloudmod: {'json': MockJson}}
2017-02-19 15:35:30 +00:00
2015-03-31 10:02:49 +00:00
def test_create(self):
'''
Test if create the named vm
'''
MockJson.flag = True
mock = MagicMock(return_value=True)
with patch.dict(saltcloudmod.__salt__, {'cmd.run_stdout': mock}):
self.assertTrue(saltcloudmod.create("webserver",
"rackspace_centos_512"
)
)
MockJson.flag = False
self.assertDictEqual(saltcloudmod.create("webserver",
"rackspace_centos_512"
),
{}
)