| 1 |
import unittest |
| 2 |
from xml.etree import ElementTree |
| 3 |
|
| 4 |
try: |
| 5 |
from unittest.mock import patch # Python 3.4 and later |
| 6 |
except ImportError: |
| 7 |
from mock import patch |
| 8 |
from ncclient import manager |
| 9 |
import ncclient.transport |
| 10 |
from ncclient.operations.third_party.sros.rpc import * |
| 11 |
from ncclient.operations import RaiseMode |
| 12 |
|
| 13 |
|
| 14 |
class TestRPC(unittest.TestCase): |
| 15 |
def setUp(self): |
| 16 |
self.device_handler = manager.make_device_handler({'name': 'sros'}) |
| 17 |
|
| 18 |
@patch('ncclient.operations.third_party.sros.rpc.RPC._request') |
| 19 |
def test_MdCliRawCommand(self, mock_request): |
| 20 |
mock_request.return_value = 'sros' |
| 21 |
expected = 'sros' |
| 22 |
session = ncclient.transport.SSHSession(self.device_handler) |
| 23 |
obj = MdCliRawCommand(session, self.device_handler) |
| 24 |
command = 'show version' |
| 25 |
actual = obj.request(command=command) |
| 26 |
self.assertEqual(expected, actual) |
| 27 |
|
| 28 |
@patch('ncclient.transport.SSHSession') |
| 29 |
@patch('ncclient.operations.third_party.sros.rpc.RPC._request') |
| 30 |
@patch('ncclient.operations.third_party.sros.rpc.RPC._assert') |
| 31 |
def test_commit(self, mock_assert, mock_request, mock_session): |
| 32 |
device_handler = manager.make_device_handler({'name': 'sros'}) |
| 33 |
session = ncclient.transport.SSHSession(device_handler) |
| 34 |
obj = Commit(session, device_handler, raise_mode=RaiseMode.ALL) |
| 35 |
|
| 36 |
obj.request(confirmed=True, comment="This is a comment", timeout="50") |
| 37 |
|
| 38 |
node = new_ele("commit") |
| 39 |
sub_ele(node, "comment", |
| 40 |
attrs={'xmlns': "urn:nokia.com:sros:ns:yang:sr:ietf-netconf-augments"}).text = "This is a comment" |
| 41 |
sub_ele(node, "confirmed") |
| 42 |
sub_ele(node, "confirm-timeout").text = "50" |
| 43 |
|
| 44 |
xml = ElementTree.tostring(node) |
| 45 |
call = mock_request.call_args_list[0][0][0] |
| 46 |
call = ElementTree.tostring(call) |
| 47 |
|
| 48 |
self.assertEqual(call, xml) |