test_client.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import pytest
  4. import salt.auth
  5. import salt.utils.platform
  6. import salt.wheel
  7. from tests.support.mixins import AdaptedConfigurationTestCaseMixin
  8. from tests.support.unit import TestCase, skipIf
  9. @pytest.mark.windows_whitelisted
  10. class WheelModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
  11. eauth_creds = {
  12. "username": "saltdev_auto",
  13. "password": "saltdev",
  14. "eauth": "auto",
  15. }
  16. def setUp(self):
  17. """
  18. Configure an eauth user to test with
  19. """
  20. self.wheel = salt.wheel.Wheel(dict(self.get_config("client_config")))
  21. def tearDown(self):
  22. del self.wheel
  23. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  24. def test_master_call(self):
  25. """
  26. Test executing master_call with lowdata
  27. The choice of using key.list_all for this is arbitrary and should be
  28. changed to some mocked function that is more testing friendly.
  29. """
  30. low = {"client": "wheel", "fun": "key.list_all", "print_event": False}
  31. low.update(self.eauth_creds)
  32. self.wheel.master_call(**low)
  33. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  34. def test_token(self):
  35. """
  36. Test executing master_call with lowdata
  37. The choice of using key.list_all for this is arbitrary and should be
  38. changed to some mocked function that is more testing friendly.
  39. """
  40. auth = salt.auth.LoadAuth(dict(self.get_config("client_config")))
  41. token = auth.mk_token(self.eauth_creds)
  42. token = auth.mk_token(
  43. {"username": "saltdev_auto", "password": "saltdev", "eauth": "auto"}
  44. )
  45. self.wheel.master_call(
  46. **{
  47. "client": "wheel",
  48. "fun": "key.list_all",
  49. "token": token["token"],
  50. "print_event": False,
  51. }
  52. )
  53. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  54. def test_cmd_sync(self):
  55. low = {
  56. "client": "wheel",
  57. "fun": "key.list_all",
  58. "print_event": False,
  59. }
  60. low.update(self.eauth_creds)
  61. self.wheel.cmd_sync(low)
  62. # Remove this skipIf when Issue #39616 is resolved
  63. # https://github.com/saltstack/salt/issues/39616
  64. @skipIf(
  65. salt.utils.platform.is_windows(),
  66. "Causes pickling error on Windows: Issue #39616",
  67. )
  68. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  69. def test_cmd_async(self):
  70. low = {
  71. "client": "wheel_async",
  72. "fun": "key.list_all",
  73. "print_event": False,
  74. }
  75. low.update(self.eauth_creds)
  76. self.wheel.cmd_async(low)
  77. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  78. def test_cmd_sync_w_arg(self):
  79. low = {
  80. "fun": "key.finger",
  81. "match": "*",
  82. "print_event": False,
  83. }
  84. low.update(self.eauth_creds)
  85. ret = self.wheel.cmd_sync(low)
  86. self.assertIn("return", ret.get("data", {}))
  87. def test_wildcard_auth(self):
  88. low = {
  89. "username": "the_s0und_of_t3ch",
  90. "password": "willrockyou",
  91. "eauth": "auto",
  92. "fun": "key.list_all",
  93. "print_event": False,
  94. }
  95. self.wheel.cmd_sync(low)