1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
import unittest
try:
from unittest.mock import patch # Python 3.4 and later
except ImportError:
from mock import patch
from ncclient import manager
import ncclient.transport
from ncclient.operations.third_party.hpcomware.rpc import *
class TestRPC(unittest.TestCase):
def setUp(self):
self.device_handler = manager.make_device_handler({'name': 'hpcomware'})
@patch('ncclient.operations.third_party.hpcomware.rpc.RPC._request')
def test_displayCommand(self, mock_request):
mock_request.return_value = 'hpcomware'
expected = 'hpcomware'
session = ncclient.transport.SSHSession(self.device_handler)
obj = DisplayCommand(session, self.device_handler)
cmds = 'show devices-name'
actual = obj.request(cmds=cmds)
self.assertEqual(expected, actual)
commands = [cmd for cmd in cmds]
actual = obj.request(cmds=commands)
self.assertEqual(expected, actual)
@patch('ncclient.operations.third_party.hpcomware.rpc.RPC._request')
def test_configCommand(self, mock_request):
mock_request.return_value = 'hpcomware'
expected = 'hpcomware'
session = ncclient.transport.SSHSession(self.device_handler)
obj = ConfigCommand(session, self.device_handler)
cmds = 'show devices-name'
actual = obj.request(cmds=cmds)
self.assertEqual(expected, actual)
commands = [cmd for cmd in cmds]
actual = obj.request(cmds=commands)
self.assertEqual(expected, actual)
@patch('ncclient.operations.third_party.hpcomware.rpc.RPC._request')
def test_action(self, mock_request):
mock_request.return_value = 'hpcomware'
expected = 'hpcomware'
session = ncclient.transport.SSHSession(self.device_handler)
obj = Action(session, self.device_handler)
action = '<get>devices-name</get>'
actual = obj.request(action=action)
self.assertEqual(expected, actual)
@patch('ncclient.operations.third_party.hpcomware.rpc.RPC._request')
def test_save(self, mock_request):
mock_request.return_value = 'hpcomware'
expected = 'hpcomware'
session = ncclient.transport.SSHSession(self.device_handler)
obj = Save(session, self.device_handler)
actual = obj.request()
self.assertEqual(expected, actual)
filename = 'devices-name'
actual = obj.request(filename=filename)
self.assertEqual(expected, actual)
@patch('ncclient.operations.third_party.hpcomware.rpc.RPC._request')
def test_rollback(self, mock_request):
mock_request.return_value = 'hpcomware'
expected = 'hpcomware'
session = ncclient.transport.SSHSession(self.device_handler)
obj = Rollback(session, self.device_handler)
actual = obj.request()
self.assertEqual(expected, actual)
filename = 'devices-name'
actual = obj.request(filename=filename)
self.assertEqual(expected, actual)
|