salt/tests/unit/modules/test_saltcloudmod.py
Erik Johnson 7b13a7df8b
Replace json module usage with a helper to ensure unicode content is handled properly
This adds wrappers for json.dump{,s} which disable `ensure_ascii` by
default.
2017-12-27 09:30:58 -06:00

49 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
import salt.modules.saltcloudmod as saltcloudmod
import salt.utils.json
@skipIf(NO_MOCK, NO_MOCK_REASON)
class SaltcloudmodTestCase(TestCase, LoaderModuleMockMixin):
'''
Test cases for salt.modules.saltcloudmod
'''
def setup_loader_modules(self):
return {saltcloudmod: {}}
def setUp(self):
self.mock_json_loads = MagicMock(side_effect=ValueError())
def test_create(self):
'''
Test if create the named vm
'''
mock = MagicMock(return_value='''{"foo": "bar"}''')
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"),
{}
)