test_zcbuildout.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import os
  4. import pytest
  5. import salt.modules.cmdmod as cmd
  6. import salt.modules.virtualenv_mod
  7. import salt.modules.zcbuildout as modbuildout
  8. import salt.states.zcbuildout as buildout
  9. import salt.utils.path
  10. from tests.support.runtests import RUNTIME_VARS
  11. from tests.support.unit import skipIf
  12. from tests.unit.modules.test_zcbuildout import KNOWN_VIRTUALENV_BINARY_NAMES, Base
  13. @skipIf(
  14. salt.utils.path.which_bin(KNOWN_VIRTUALENV_BINARY_NAMES) is None,
  15. "The 'virtualenv' packaged needs to be installed",
  16. )
  17. class BuildoutTestCase(Base):
  18. def setup_loader_modules(self):
  19. module_globals = {
  20. "__env__": "base",
  21. "__opts__": {"test": False},
  22. "__salt__": {
  23. "cmd.run_all": cmd.run_all,
  24. "cmd.run": cmd.run,
  25. "cmd.retcode": cmd.retcode,
  26. "buildout.buildout": modbuildout.buildout,
  27. },
  28. }
  29. return {buildout: module_globals, modbuildout: module_globals}
  30. # I don't have the time to invest in learning more about buildout,
  31. # and given we don't have support yet, and there are other priorities
  32. # I'm going to punt on this for now - WW
  33. @skipIf(True, "Buildout is still in beta. Test needs fixing.")
  34. @pytest.mark.requires_network
  35. def test_quiet(self):
  36. c_dir = os.path.join(self.tdir, "c")
  37. assert False, os.listdir(self.rdir)
  38. modbuildout.upgrade_bootstrap(c_dir)
  39. cret = buildout.installed(c_dir, python=self.py_st)
  40. self.assertFalse("OUTPUT:" in cret["comment"], cret["comment"])
  41. self.assertFalse("Log summary:" in cret["comment"], cret["comment"])
  42. self.assertTrue(cret["result"], cret["comment"])
  43. @pytest.mark.requires_network
  44. @pytest.mark.slow_test(seconds=5) # Test takes >1 and <=5 seconds
  45. def test_error(self):
  46. b_dir = os.path.join(self.tdir, "e")
  47. ret = buildout.installed(b_dir, python=self.py_st)
  48. self.assertTrue(
  49. "We did not get any expectable answer from buildout" in ret["comment"]
  50. )
  51. self.assertFalse(ret["result"])
  52. @pytest.mark.requires_network
  53. @pytest.mark.slow_test(seconds=10) # Test takes >5 and <=10 seconds
  54. def test_installed(self):
  55. if salt.modules.virtualenv_mod.virtualenv_ver(self.ppy_st) >= (20, 0, 0):
  56. self.skipTest(
  57. "Skiping until upstream resolved https://github.com/pypa/virtualenv/issues/1715"
  58. )
  59. b_dir = os.path.join(self.tdir, "b")
  60. ret = buildout.installed(
  61. b_dir, python=self.py_st, onlyif=RUNTIME_VARS.SHELL_FALSE_PATH
  62. )
  63. self.assertEqual(ret["comment"], "\nonlyif condition is false")
  64. self.assertEqual(ret["result"], True)
  65. self.assertTrue(os.sep + "b" in ret["name"])
  66. b_dir = os.path.join(self.tdir, "b")
  67. ret = buildout.installed(
  68. b_dir, python=self.py_st, unless=RUNTIME_VARS.SHELL_TRUE_PATH
  69. )
  70. self.assertEqual(ret["comment"], "\nunless condition is true")
  71. self.assertEqual(ret["result"], True)
  72. self.assertTrue(os.sep + "b" in ret["name"])
  73. ret = buildout.installed(b_dir, python=self.py_st)
  74. self.assertEqual(ret["result"], True)
  75. self.assertTrue("OUTPUT:" in ret["comment"])
  76. self.assertTrue("Log summary:" in ret["comment"])