mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
mock ncclient import in test_connection.py (#32786)
This commit is contained in:
parent
4c58ad1266
commit
35f79370e1
1 changed files with 22 additions and 1 deletions
|
@ -20,9 +20,12 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
from io import StringIO
|
||||
import sys
|
||||
|
||||
from ansible.compat.tests import mock
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import MagicMock
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
from ansible.plugins.connection import ConnectionBase
|
||||
|
@ -37,9 +40,27 @@ from ansible.plugins.connection.paramiko_ssh import Connection as ParamikoConnec
|
|||
from ansible.plugins.connection.ssh import Connection as SSHConnection
|
||||
from ansible.plugins.connection.docker import Connection as DockerConnection
|
||||
# from ansible.plugins.connection.winrm import Connection as WinRmConnection
|
||||
from ansible.plugins.connection.netconf import Connection as NetconfConnection
|
||||
from ansible.plugins.connection.network_cli import Connection as NetworkCliConnection
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
builtin_import = __import__
|
||||
|
||||
mock_ncclient = MagicMock(name='ncclient')
|
||||
|
||||
|
||||
def import_mock(name, *args):
|
||||
if name.startswith('ncclient'):
|
||||
return mock_ncclient
|
||||
return builtin_import(name, *args)
|
||||
|
||||
if PY3:
|
||||
with patch('builtins.__import__', side_effect=import_mock):
|
||||
from ansible.plugins.connection.netconf import Connection as NetconfConnection
|
||||
else:
|
||||
with patch('__builtin__.__import__', side_effect=import_mock):
|
||||
from ansible.plugins.connection.netconf import Connection as NetconfConnection
|
||||
|
||||
|
||||
class TestConnectionBaseClass(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in a new issue