Skip to content

Commit

Permalink
Merge pull request #193 from Juniper/unit-tests
Browse files Browse the repository at this point in the history
Unit tests - exception and rpcmeta
  • Loading branch information
shermdog committed May 6, 2014
2 parents c5d691a + b1743a6 commit 0421dea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/unit/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import unittest
from nose.plugins.attrib import attr
from jnpr.junos.exception import RpcError, CommitError
from jnpr.junos.exception import RpcError, CommitError, ConnectError
from jnpr.junos import Device
from lxml import etree


Expand All @@ -17,7 +18,16 @@ def test_rpcerror_repr(self):
self.assertEqual(obj.__repr__(), '<root>\n <a>test</a>\n</root>\n')

def test_rpcerror_jxml_check(self):
#this test is intended to hit jxml code
# this test is intended to hit jxml code
rsp = etree.XML('<rpc-reply><a>test</a></rpc-reply>')
obj = CommitError(rsp=rsp)
self.assertEqual(type(obj.rpc_error), dict)

def test_ConnectError(self):
self.dev = Device(host='1.1.1.1', user='rick', password='password123',
gather_facts=False)
obj = ConnectError(self.dev)
self.assertEqual(obj.user, 'rick')
self.assertEqual(obj.host, '1.1.1.1')
self.assertEqual(obj.port, 830)
self.assertEqual(repr(obj), 'ConnectError(1.1.1.1)')
7 changes: 7 additions & 0 deletions tests/unit/test_rpcmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ def test_rpcmeta_exec_rpc_kvargs(self, mock_execute_fn):
self.rpc.system_users_information(set_data=('test',))
self.assertEqual(mock_execute_fn.call_args[0][0][0].text,
'test')

@patch('jnpr.junos.device.Device.execute')
def test_rpcmeta_get_config(self, mock_execute_fn):
root = etree.XML('<root><a>test</a></root>')
self.rpc.get_config(root)
self.assertEqual(mock_execute_fn.call_args[0][0].tag,
'get-configuration')

0 comments on commit 0421dea

Please sign in to comment.