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
|
2017-02-27 13:58:07 +00:00
|
|
|
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
|
2017-12-22 19:54:53 +00:00
|
|
|
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
|
|
|
|
'''
|
2017-03-22 12:12:36 +00:00
|
|
|
def setup_loader_modules(self):
|
2017-12-22 19:54:53 +00:00
|
|
|
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
|
|
|
|
'''
|
2017-12-22 19:54:53 +00:00
|
|
|
mock = MagicMock(return_value='''{"foo": "bar"}''')
|
2015-03-31 10:02:49 +00:00
|
|
|
with patch.dict(saltcloudmod.__salt__, {'cmd.run_stdout': mock}):
|
2017-12-22 19:54:53 +00:00
|
|
|
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"),
|
|
|
|
{}
|
|
|
|
)
|