test_libcloud_dns.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Anthony Shaw <anthonyshaw@apache.org>
  4. """
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import salt.modules.libcloud_dns as libcloud_dns
  8. # Import Salt Testing Libs
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.mock import MagicMock, patch
  11. from tests.support.unit import TestCase, skipIf
  12. class MockDNSDriver(object):
  13. def __init__(self):
  14. pass
  15. def get_mock_driver():
  16. return MockDNSDriver()
  17. @skipIf(not libcloud_dns.HAS_LIBCLOUD, "No libcloud installed")
  18. class LibcloudDnsModuleTestCase(TestCase, LoaderModuleMockMixin):
  19. def setup_loader_modules(self):
  20. module_globals = {
  21. "_get_driver": MagicMock(return_value=MockDNSDriver()),
  22. "__salt__": {
  23. "config.option": MagicMock(
  24. return_value={"test": {"driver": "test", "key": "2orgk34kgk34g"}}
  25. )
  26. },
  27. }
  28. if libcloud_dns.HAS_LIBCLOUD is False:
  29. module_globals["sys.modules"] = {"libcloud": MagicMock()}
  30. return {libcloud_dns: module_globals}
  31. def test_module_creation(self):
  32. client = libcloud_dns._get_driver("test")
  33. self.assertFalse(client is None)
  34. def test_init(self):
  35. with patch("salt.utils.compat.pack_dunder", return_value=False) as dunder:
  36. libcloud_dns.__init__(None)
  37. dunder.assert_called_with("salt.modules.libcloud_dns")