1from units.compat import mock 2from units.compat import unittest 3 4from ansible.modules.packaging.os import apk 5 6 7class TestApkQueryLatest(unittest.TestCase): 8 9 def setUp(self): 10 self.module_names = [ 11 'bash', 12 'g++', 13 ] 14 15 @mock.patch('ansible.modules.packaging.os.apk.AnsibleModule') 16 def test_not_latest(self, mock_module): 17 apk.APK_PATH = "" 18 for module_name in self.module_names: 19 command_output = module_name + '-2.0.0-r1 < 3.0.0-r2 ' 20 mock_module.run_command.return_value = (0, command_output, None) 21 command_result = apk.query_latest(mock_module, module_name) 22 self.assertFalse(command_result) 23 24 @mock.patch('ansible.modules.packaging.os.apk.AnsibleModule') 25 def test_latest(self, mock_module): 26 apk.APK_PATH = "" 27 for module_name in self.module_names: 28 command_output = module_name + '-2.0.0-r1 = 2.0.0-r1 ' 29 mock_module.run_command.return_value = (0, command_output, None) 30 command_result = apk.query_latest(mock_module, module_name) 31 self.assertTrue(command_result) 32