1
0
Fork 0
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:
Frederic Lepied 2017-11-10 17:53:04 +01:00 committed by Nathaniel Case
parent 4c58ad1266
commit 35f79370e1

View file

@ -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):