test_guestfs.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch,
  13. )
  14. # Import Salt Libs
  15. import salt.modules.guestfs as guestfs
  16. class GuestfsTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.modules.guestfs
  19. '''
  20. def setup_loader_modules(self):
  21. return {guestfs: {}}
  22. # 'mount' function tests: 1
  23. def test_mount(self):
  24. '''
  25. Test if it mount an image
  26. '''
  27. with patch('os.path.join', MagicMock(return_value=True)), \
  28. patch('os.path.isdir', MagicMock(return_value=True)), \
  29. patch('os.listdir', MagicMock(return_value=False)), \
  30. patch.dict(guestfs.__salt__, {'cmd.run': MagicMock(return_value='')}):
  31. self.assertTrue(guestfs.mount('/srv/images/fedora.qcow'))