test_proxy.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """
  3. Unit tests for salt.utils.proxy
  4. :codeauthor: :email:`Gareth J. Greenaway <gareth@saltstack.com>`
  5. """
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import salt.utils.proxy
  8. from tests.support.mock import patch
  9. from tests.support.unit import TestCase
  10. class ProxyUtilsTestCase(TestCase):
  11. def test_is_proxytype_true(self):
  12. opts = {
  13. "proxy": {
  14. "proxytype": "esxi",
  15. "host": "esxi.domain.com",
  16. "username": "username",
  17. "passwords": ["password1"],
  18. }
  19. }
  20. with patch("salt.utils.platform.is_proxy", return_value=True, autospec=True):
  21. ret = salt.utils.proxy.is_proxytype(opts, "esxi")
  22. self.assertTrue(ret)
  23. def test_is_proxytype_false(self):
  24. opts = {
  25. "proxy": {
  26. "proxytype": "esxi",
  27. "host": "esxi.domain.com",
  28. "username": "username",
  29. "passwords": ["password1"],
  30. }
  31. }
  32. with patch("salt.utils.platform.is_proxy", return_value=True, autospec=True):
  33. ret = salt.utils.proxy.is_proxytype(opts, "docker")
  34. self.assertFalse(ret)
  35. def test_is_proxytype_not_proxy(self):
  36. opts = {}
  37. with patch("salt.utils.platform.is_proxy", return_value=False, autospec=True):
  38. ret = salt.utils.proxy.is_proxytype(opts, "docker")
  39. self.assertFalse(ret)