| 1 |
import unittest |
| 2 |
try: |
| 3 |
from unittest.mock import patch # Python 3.4 and later |
| 4 |
except ImportError: |
| 5 |
from mock import patch |
| 6 |
from ncclient import manager |
| 7 |
import ncclient.transport |
| 8 |
from ncclient.operations.third_party.nexus.rpc import * |
| 9 |
|
| 10 |
|
| 11 |
class TestRPC(unittest.TestCase): |
| 12 |
def setUp(self): |
| 13 |
self.device_handler = manager.make_device_handler({'name': 'nexus'}) |
| 14 |
|
| 15 |
@patch('ncclient.operations.third_party.nexus.rpc.RPC._request') |
| 16 |
def test_execCommand(self, mock_request): |
| 17 |
mock_request.return_value = 'nexus' |
| 18 |
expected = 'nexus' |
| 19 |
session = ncclient.transport.SSHSession(self.device_handler) |
| 20 |
obj = ExecCommand(session, self.device_handler) |
| 21 |
cmds = 'show devices-name' |
| 22 |
actual = obj.request(cmds=cmds) |
| 23 |
self.assertEqual(expected, actual) |
| 24 |
|
| 25 |
commands = [cmd for cmd in cmds] |
| 26 |
actual = obj.request(cmds=commands) |
| 27 |
self.assertEqual(expected, actual) |