salt/tests/unit/modules/test_qemu_img.py

54 lines
1.7 KiB
Python
Raw Normal View History

2015-04-23 12:43:27 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Rupesh Tare <rupesht@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
2017-03-22 16:42:17 +00:00
import os
2015-04-23 12:43:27 +00:00
# Import Salt Testing Libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
2015-04-23 12:43:27 +00:00
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
import salt.modules.qemu_img as qemu_img
2015-04-23 12:43:27 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class QemuimgTestCase(TestCase, LoaderModuleMockMixin):
2015-04-23 12:43:27 +00:00
'''
Test cases for salt.modules.qemu_img
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {qemu_img: {}}
2015-04-23 12:43:27 +00:00
def test_make_image(self):
'''
Test for create a blank virtual machine image file
of the specified size in megabytes
'''
with patch.object(os.path, 'isabs',
MagicMock(side_effect=[False, True, True, True])):
self.assertEqual(qemu_img.make_image('location', 'size', 'fmt'), '')
with patch.object(os.path, 'isdir',
MagicMock(side_effect=[False, True, True])):
self.assertEqual(qemu_img.make_image('location', 'size', 'fmt'),
'')
with patch.dict(qemu_img.__salt__,
{'cmd.retcode': MagicMock(side_effect=[False,
True])}):
self.assertEqual(qemu_img.make_image('location', 'size',
'fmt'), 'location')
self.assertEqual(qemu_img.make_image('location', 'size',
'fmt'), '')