Skip to content

Commit

Permalink
test cases for junos proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitin Kumar authored and dwoz committed May 18, 2020
1 parent ac3bf1c commit 69f59a4
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/unit/proxy/test_junos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import salt.proxy.junos as junos

import sys

# Import Salt Testing Libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
from tests.support.unit import TestCase, skipIf

if sys.version < "3":
from six import StringIO
else:
from io import BytesIO as StringIO

try:
from jnpr.junos.device import Device
from jnpr.junos.exception import ConnectError
import jxmlease # pylint: disable=unused-import
from ncclient.transport.ssh import SSHSession
from ncclient.devices.junos import JunosDeviceHandler

HAS_JUNOS = True
except ImportError:
HAS_JUNOS = False


@skipIf(not HAS_JUNOS, "The junos-eznc and jxmlease modules are required")
class JunosProxyTestCase(TestCase, LoaderModuleMockMixin):
def setup_loader_modules(self):
return {
junos: {
"__virtual__": MagicMock(return_value="junos"),
"DETAILS": {},
"__pillar__": {},
}
}

def setUp(self):
self.opts = {"proxy": {"username": "xxxx", "password]": "xxx", "host": "junos"}}

@patch("ncclient.manager.connect")
def test_init(self, mock_connect):
junos.init(self.opts)
self.assertTrue(junos.thisproxy.get("initialized"))

@patch("ncclient.manager.connect")
def test_init_err(self, mock_connect):
mock_connect.side_effect = ConnectError
junos.init(self.opts)
self.assertFalse(junos.thisproxy.get("initialized"))

@patch("ncclient.manager.connect")
def test_alive(self, mock_connect):
junos.init(self.opts)
junos.thisproxy["conn"]._conn._session._buffer = StringIO()
self.assertTrue(junos.alive(self.opts))
self.assertTrue(junos.thisproxy.get("initialized"))

0 comments on commit 69f59a4

Please sign in to comment.