1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pip module: fix TypeError (#31395)

* pip: add test: an error occurs when pip not found
* pip: fix TypeError exception when pip executable isn't found
This commit is contained in:
Pilou 2017-10-09 19:01:21 +02:00 committed by Matt Clay
parent 5e9384300d
commit 1c9bffe248
6 changed files with 31 additions and 5 deletions

View file

@ -286,7 +286,7 @@ def _get_pip(module, env=None, executable=None):
else:
# For-else: Means that we did not break out of the loop
# (therefore, that pip was not found)
module.fail_json(msg='Unable to find any of %s to use. pip' +
module.fail_json(msg='Unable to find any of %s to use. pip'
' needs to be installed.' % ', '.join(candidate_pip_basenames))
else:
# If we're using a virtualenv we must use the pip from the

View file

@ -0,0 +1,26 @@
import json
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch
from ansible.module_utils import basic
from ansible.modules.packaging.language import pip
from ..utils import (set_module_args, AnsibleFailJson, exit_json, fail_json)
class TestPip(unittest.TestCase):
def setUp(self):
self.mock_ansible_module = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
self.mock_ansible_module.start()
self.addCleanup(self.mock_ansible_module.stop)
@patch.object(basic.AnsibleModule, 'get_bin_path')
def test_failure_when_pip_absent(self, mock_get_bin_path):
mock_get_bin_path.return_value = None
with self.assertRaises(AnsibleFailJson):
set_module_args({'name': 'six'})
pip.main()

View file

@ -7,8 +7,8 @@ from ansible.module_utils.six.moves import xmlrpc_client
from ansible.module_utils._text import to_bytes
from ansible.modules.packaging.os import rhn_channel
from .rhn_utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
exit_json, fail_json, get_method_name, mock_request)
from ..utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
exit_json, fail_json, get_method_name, mock_request)
class TestRhnChannel(unittest.TestCase):

View file

@ -7,8 +7,8 @@ from ansible.module_utils._text import to_native
from ansible.module_utils.six.moves import xmlrpc_client
from ansible.modules.packaging.os import rhn_register
from .rhn_utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
exit_json, fail_json, get_method_name, mock_request)
from ..utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
exit_json, fail_json, get_method_name, mock_request)
SYSTEMID = """<?xml version="1.0"?>