test_baredoc.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import
  4. import os
  5. # Import module
  6. import salt.modules.baredoc as baredoc
  7. from tests.support.mixins import LoaderModuleMockMixin
  8. from tests.support.runtests import RUNTIME_VARS
  9. # Import Salt Testing Libs
  10. from tests.support.unit import TestCase
  11. class BaredocTest(TestCase, LoaderModuleMockMixin):
  12. """
  13. Validate baredoc module
  14. """
  15. def setup_loader_modules(self):
  16. return {
  17. baredoc: {
  18. "__opts__": {
  19. "extension_modules": os.path.join(RUNTIME_VARS.CODE_DIR, "salt"),
  20. },
  21. "__grains__": {"saltpath": os.path.join(RUNTIME_VARS.CODE_DIR, "salt")},
  22. }
  23. }
  24. def test_baredoc_list_states(self):
  25. """
  26. Test baredoc state module listing
  27. """
  28. ret = baredoc.list_states(names_only=True)
  29. assert "value_present" in ret["xml"][0]
  30. def test_baredoc_list_states_args(self):
  31. """
  32. Test baredoc state listing with args
  33. """
  34. ret = baredoc.list_states()
  35. assert "value_present" in ret["xml"][0]
  36. assert "xpath" in ret["xml"][0]["value_present"]
  37. def test_baredoc_list_states_single(self):
  38. """
  39. Test baredoc state listing single state module
  40. """
  41. ret = baredoc.list_states("xml")
  42. assert "value_present" in ret["xml"][0]
  43. assert "xpath" in ret["xml"][0]["value_present"]
  44. def test_baredoc_list_modules(self):
  45. """
  46. test baredoc executiion module listing
  47. """
  48. ret = baredoc.list_modules(names_only=True)
  49. assert "get_value" in ret["xml"][0]
  50. def test_baredoc_list_modules_args(self):
  51. """
  52. test baredoc execution module listing with args
  53. """
  54. ret = baredoc.list_modules()
  55. assert "get_value" in ret["xml"][0]
  56. assert "file" in ret["xml"][0]["get_value"]
  57. def test_baredoc_list_modules_single_and_alias(self):
  58. """
  59. test baredoc single module listing
  60. """
  61. ret = baredoc.list_modules("mdata")
  62. assert "put" in ret["mdata"][2]
  63. assert "keyname" in ret["mdata"][2]["put"]
  64. def test_baredoc_state_docs(self):
  65. ret = baredoc.state_docs()
  66. assert "XML Manager" in ret["xml"]
  67. assert "zabbix_usergroup" in ret
  68. def test_baredoc_state_docs_single_arg(self):
  69. ret = baredoc.state_docs("xml")
  70. assert "XML Manager" in ret["xml"]
  71. ret = baredoc.state_docs("xml.value_present")
  72. assert "Manages a given XML file" in ret["xml.value_present"]
  73. def test_baredoc_state_docs_multiple_args(self):
  74. ret = baredoc.state_docs("zabbix_hostgroup.present", "xml")
  75. assert "Ensures that the host group exists" in ret["zabbix_hostgroup.present"]
  76. assert "XML Manager" in ret["xml"]
  77. assert "Manages a given XML file" in ret["xml.value_present"]
  78. def test_baredoc_module_docs(self):
  79. ret = baredoc.module_docs()
  80. assert "A module for testing" in ret["saltcheck"]
  81. def test_baredoc_module_docs_single_arg(self):
  82. ret = baredoc.module_docs("saltcheck")
  83. assert "A module for testing" in ret["saltcheck"]
  84. def test_baredoc_module_docs_multiple_args(self):
  85. ret = baredoc.module_docs("saltcheck", "xml.get_value")
  86. assert "A module for testing" in ret["saltcheck"]
  87. assert "Returns the value of the matched xpath element" in ret["xml.get_value"]