salt/tests/integration/modules/mac_ports.py

124 lines
3.4 KiB
Python
Raw Normal View History

2016-03-23 23:48:47 +00:00
# -*- coding: utf-8 -*-
'''
integration tests for mac_ports
'''
# Import python libs
from __future__ import absolute_import, print_function
# Import Salt Testing libs
from salttesting.helpers import ensure_in_syspath, destructiveTest
ensure_in_syspath('../../')
# Import salt libs
import integration
import salt.utils
class MacPortsModuleTest(integration.ModuleCase):
'''
Validate the mac_ports module
'''
2016-03-24 00:09:27 +00:00
AGREE_INSTALLED = False
2016-03-23 23:48:47 +00:00
def setUp(self):
'''
Get current settings
'''
if not salt.utils.is_darwin():
self.skipTest('Test only available on Mac OS X')
if not salt.utils.which('port'):
self.skipTest('Test requires port binary')
if salt.utils.get_uid(salt.utils.get_user()) != 0:
self.skipTest('Test requires root')
2016-03-24 00:07:00 +00:00
self.AGREE_INSTALLED = 'agree' in self.run_function('pkg.list_pkgs')
2016-03-24 00:18:28 +00:00
self.run_function('pkg.refresh_db')
2016-03-24 00:07:00 +00:00
2016-03-23 23:48:47 +00:00
def tearDown(self):
'''
Reset to original settings
'''
2016-03-24 00:07:00 +00:00
if not self.AGREE_INSTALLED:
self.run_function('pkg.remove', ['agree'])
2016-03-23 23:48:47 +00:00
2016-03-24 00:18:28 +00:00
@destructiveTest
2016-03-23 23:48:47 +00:00
def test_list_pkgs(self):
'''
Test pkg.list_pkgs
'''
2016-03-24 00:07:00 +00:00
self.run_function('pkg.install', ['agree'])
2016-03-23 23:48:47 +00:00
self.assertIsInstance(self.run_function('pkg.list_pkgs'), dict)
self.assertIn('agree', self.run_function('pkg.list_pkgs'))
2016-03-24 00:18:28 +00:00
@destructiveTest
2016-03-23 23:48:47 +00:00
def test_latest_version(self):
'''
Test pkg.latest_version
'''
2016-03-24 00:07:00 +00:00
self.run_function('pkg.install', ['agree'])
2016-03-24 00:18:28 +00:00
result = self.run_function('pkg.latest_version',
['agree'],
2016-03-24 00:26:38 +00:00
refresh=False)
2016-03-24 00:18:28 +00:00
self.assertIsInstance(result, dict)
self.assertIn('agree', result)
2016-03-23 23:48:47 +00:00
2016-03-24 00:18:28 +00:00
@destructiveTest
2016-03-23 23:48:47 +00:00
def test_remove(self):
'''
Test pkg.remove
'''
2016-03-24 00:07:00 +00:00
self.run_function('pkg.install', ['agree'])
2016-03-23 23:48:47 +00:00
removed = self.run_function('pkg.remove', ['agree'])
self.assertIsInstance(removed, dict)
self.assertIn('agree', removed)
2016-03-24 00:18:28 +00:00
@destructiveTest
2016-03-23 23:48:47 +00:00
def test_install(self):
'''
Test pkg.install
'''
2016-03-24 00:07:00 +00:00
self.run_function('pkg.remove', ['agree'])
2016-03-23 23:48:47 +00:00
installed = self.run_function('pkg.install', ['agree'])
self.assertIsInstance(installed, dict)
self.assertIn('agree', installed)
def test_list_upgrades(self):
'''
Test pkg.list_upgrades
'''
2016-03-24 00:18:28 +00:00
self.assertIsInstance(
self.run_function('pkg.list_upgrades', refresh=False), dict)
2016-03-23 23:48:47 +00:00
2016-03-24 00:18:28 +00:00
@destructiveTest
2016-03-23 23:48:47 +00:00
def test_upgrade_available(self):
'''
Test pkg.upgrade_available
'''
self.run_function('pkg.install', ['agree'])
2016-03-24 00:18:28 +00:00
self.assertFalse(self.run_function('pkg.upgrade_available',
['agree'],
refresh=False))
2016-03-23 23:48:47 +00:00
def test_refresh_db(self):
'''
Test pkg.refresh_db
'''
self.assertTrue(self.run_function('pkg.refresh_db'))
2016-03-24 00:18:28 +00:00
@destructiveTest
2016-03-23 23:48:47 +00:00
def test_upgrade(self):
'''
Test pkg.upgrade
'''
2016-03-24 00:18:28 +00:00
results = self.run_function('pkg.upgrade', refresh=False)
2016-03-23 23:48:47 +00:00
self.assertIsInstance(results, dict)
self.assertTrue(results['result'])
if __name__ == '__main__':
from integration import run_tests
run_tests(MacPortsModuleTest)