Skip to content

Commit

Permalink
rpc unit test 100% coverage (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
maercu authored Jul 9, 2023
1 parent 347d1d2 commit 8cb11ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ def sros_rpc_payload():
"""


@pytest.fixture(scope="function", autouse=True)
def sros_rpc_payload_action():
return """
<action xmlns="urn:ietf:params:xml:ns:yang:1">
<admin xmlns="urn:nokia.com:sros:ns:yang:sr:oper-admin">
<clear>
<security>
<password-history>
<all/>
</password-history>
</security>
</clear>
</admin>
</action>
"""


def xml_dict(xml: str) -> Dict[str, Any]:
"""Convert XML to Dict.
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/schema_path/nokia-conf-aaa.yang

This file was deleted.

14 changes: 14 additions & 0 deletions tests/unit/test_netconf_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ def test_netconf_rpc_success(ssh, nornir, sros_rpc_payload):
assert result[DEVICE_NAME].result.rpc.ok


@patch("ncclient.manager.connect_ssh")
def test_netconf_rpc_success_action(ssh, nornir, sros_rpc_payload_action):
"""Test NETCONF rpc action (namespace set), no defined manager."""
response_rpc = MagicMock()
response = MagicMock()
response.rpc.return_value = response_rpc
ssh.return_value = response

nr = nornir.filter(name=DEVICE_NAME)
result = nr.run(netconf_rpc, payload=sros_rpc_payload_action)
assert not result[DEVICE_NAME].failed
assert result[DEVICE_NAME].result.rpc.ok


@patch("ncclient.manager.connect_ssh")
def test_netconf_rpc_manager_set(ssh, nornir, sros_rpc_payload):
"""Test NETCONF rpc, with manager option set."""
Expand Down

0 comments on commit 8cb11ae

Please sign in to comment.