salt/tests/unit/modules/test_saltcloudmod.py

49 lines
1.4 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, print_function, unicode_literals
2015-03-31 10:02:49 +00:00
# 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
import salt.utils.json
2015-03-31 10:02:49 +00:00
@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: {}}
def setUp(self):
self.mock_json_loads = MagicMock(side_effect=ValueError())
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
'''
mock = MagicMock(return_value='''{"foo": "bar"}''')
2015-03-31 10:02:49 +00:00
with patch.dict(saltcloudmod.__salt__, {'cmd.run_stdout': mock}):
self.assertTrue(
saltcloudmod.create("webserver", "rackspace_centos_512"))
with patch.object(salt.utils.json, 'loads', self.mock_json_loads):
self.assertDictEqual(
saltcloudmod.create("webserver", "rackspace_centos_512"),
{}
)