1
0

test_idem.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """
  2. Test utility methods that the idem module and state share
  3. """
  4. from contextlib import contextmanager
  5. import salt.utils.idem as idem
  6. import salt.utils.path
  7. from tests.support.case import TestCase
  8. from tests.support.unit import skipIf
  9. HAS_IDEM = not salt.utils.path.which("idem")
  10. @skipIf(not idem.HAS_POP[0], str(idem.HAS_POP[1]))
  11. @contextmanager
  12. class TestIdem(TestCase):
  13. @classmethod
  14. def setUpClass(cls):
  15. cls.hub = idem.hub()
  16. def test_loop(self):
  17. assert hasattr(self.hub.pop, "Loop")
  18. def test_subs(self):
  19. for sub in ("acct", "config", "idem", "exec", "states"):
  20. with self.subTest(sub=sub):
  21. assert hasattr(self.hub, sub)
  22. @skipIf(not HAS_IDEM, "idem is not installed")
  23. def test_idem_ex(self):
  24. assert hasattr(self.hub.idem, "ex")
  25. @skipIf(not HAS_IDEM, "idem is not installed")
  26. def test_idem_state_apply(self):
  27. assert hasattr(self.hub.idem.state, "apply")
  28. @skipIf(not HAS_IDEM, "idem is not installed")
  29. def test_idem_exec(self):
  30. # self.hub.exec.test.ping() causes a pylint error because of "exec" in the namespace
  31. assert getattr(self.hub, "exec").test.ping()
  32. @skipIf(not HAS_IDEM, "idem is not installed")
  33. def test_idem_state(self):
  34. ret = self.hub.states.test.succeed_without_changes({}, "test_state")
  35. assert ret["result"] is True
  36. def test_config(self):
  37. assert self.hub.OPT.acct
  38. assert self.hub.OPT.idem