test_mac_portspkg.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # -*- coding: utf-8 -*-
  2. '''
  3. integration tests for mac_ports
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, unicode_literals, print_function
  7. import pytest
  8. # Import Salt Testing libs
  9. from tests.support.case import ModuleCase
  10. # Import Salt libs
  11. import salt.utils.path
  12. import salt.utils.platform
  13. @pytest.mark.skip_if_not_root
  14. class MacPortsModuleTest(ModuleCase):
  15. '''
  16. Validate the mac_ports module
  17. '''
  18. AGREE_INSTALLED = False
  19. def setUp(self):
  20. '''
  21. Get current settings
  22. '''
  23. if not salt.utils.platform.is_darwin():
  24. self.skipTest('Test only available on macOS')
  25. if not salt.utils.path.which('port'):
  26. self.skipTest('Test requires port binary')
  27. self.AGREE_INSTALLED = 'agree' in self.run_function('pkg.list_pkgs')
  28. self.run_function('pkg.refresh_db')
  29. def tearDown(self):
  30. '''
  31. Reset to original settings
  32. '''
  33. if not self.AGREE_INSTALLED:
  34. self.run_function('pkg.remove', ['agree'])
  35. @pytest.mark.destructive_test
  36. def test_list_pkgs(self):
  37. '''
  38. Test pkg.list_pkgs
  39. '''
  40. self.run_function('pkg.install', ['agree'])
  41. self.assertIsInstance(self.run_function('pkg.list_pkgs'), dict)
  42. self.assertIn('agree', self.run_function('pkg.list_pkgs'))
  43. @pytest.mark.destructive_test
  44. def test_latest_version(self):
  45. '''
  46. Test pkg.latest_version
  47. '''
  48. self.run_function('pkg.install', ['agree'])
  49. result = self.run_function('pkg.latest_version',
  50. ['agree'],
  51. refresh=False)
  52. self.assertIsInstance(result, dict)
  53. self.assertIn('agree', result)
  54. @pytest.mark.destructive_test
  55. def test_remove(self):
  56. '''
  57. Test pkg.remove
  58. '''
  59. self.run_function('pkg.install', ['agree'])
  60. removed = self.run_function('pkg.remove', ['agree'])
  61. self.assertIsInstance(removed, dict)
  62. self.assertIn('agree', removed)
  63. @pytest.mark.destructive_test
  64. def test_install(self):
  65. '''
  66. Test pkg.install
  67. '''
  68. self.run_function('pkg.remove', ['agree'])
  69. installed = self.run_function('pkg.install', ['agree'])
  70. self.assertIsInstance(installed, dict)
  71. self.assertIn('agree', installed)
  72. def test_list_upgrades(self):
  73. '''
  74. Test pkg.list_upgrades
  75. '''
  76. self.assertIsInstance(
  77. self.run_function('pkg.list_upgrades', refresh=False), dict)
  78. @pytest.mark.destructive_test
  79. def test_upgrade_available(self):
  80. '''
  81. Test pkg.upgrade_available
  82. '''
  83. self.run_function('pkg.install', ['agree'])
  84. self.assertFalse(self.run_function('pkg.upgrade_available',
  85. ['agree'],
  86. refresh=False))
  87. def test_refresh_db(self):
  88. '''
  89. Test pkg.refresh_db
  90. '''
  91. self.assertTrue(self.run_function('pkg.refresh_db'))
  92. @pytest.mark.destructive_test
  93. def test_upgrade(self):
  94. '''
  95. Test pkg.upgrade
  96. '''
  97. results = self.run_function('pkg.upgrade', refresh=False)
  98. self.assertIsInstance(results, dict)
  99. self.assertTrue(results['result'])