<s> __author__ = "<STR_LIT>" <EOL> __credits__ = "<STR_LIT>" <EOL> import unittest <EOL> from nose . plugins . attrib import attr <EOL> from mock import MagicMock <EOL> from jnpr . junos import Device <EOL> from jnpr . junos . factory . view import View <EOL> from jnpr . junos . op . phyport import PhyPortStatsTable , PhyPortStatsView <EOL> from lxml import etree <EOL> @ attr ( '<STR_LIT>' ) <EOL> class TestFactoryView ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . dev = Device ( host = '<STR_LIT>' , user = '<STR_LIT>' , password = '<STR_LIT>' , <EOL> gather_facts = False ) <EOL> self . ppt = PhyPortStatsTable ( self . dev ) <EOL> ret_val = '<STR_LIT>' <EOL> xml = etree . fromstring ( ret_val ) <EOL> self . v = PhyPortStatsView ( self . ppt , xml ) <EOL> def test_view_init ( self ) : <EOL> self . assertEqual ( self . v . key , '<STR_LIT>' ) <EOL> def test_view_init_multi_exception ( self ) : <EOL> self . assertRaises ( ValueError , View , self . ppt , [ '<STR_LIT:test>' , '<STR_LIT>' ] ) <EOL> def test_view_init_lxml_exception ( self ) : <EOL> self . assertRaises ( ValueError , View , self . ppt , [ '<STR_LIT:test>' ] ) <EOL> def test_view_repr ( self ) : <EOL> self . assertEqual ( str ( self . v ) , '<STR_LIT>' ) <EOL> def test_view_d ( self ) : <EOL> self . assertEqual ( self . v . D , self . dev ) <EOL> def test_view_name ( self ) : <EOL> self . assertEqual ( self . v . name , '<STR_LIT>' ) <EOL> def test_view_name_xpath_none ( self ) : <EOL> self . v . ITEM_NAME_XPATH = None <EOL> self . assertEqual ( self . v . name , '<STR_LIT>' ) <EOL> def test_view_name_xpath_composite ( self ) : <EOL> self . v . ITEM_NAME_XPATH = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( self . v . name , ( '<STR_LIT>' , None , '<STR_LIT>' ) ) <EOL> def test_view_asview ( self ) : <EOL> self . assertEqual ( <EOL> type ( <EOL> self . v . asview ( PhyPortStatsTable ) ) , <EOL> PhyPortStatsTable ) <EOL> def test_view_refresh_can_refresh_false ( self ) : <EOL> self . v . _table . can_refresh = False <EOL> self . assertRaises ( RuntimeError , self . v . refresh ) <EOL> def test_view_refresh_can_refresh_true ( self ) : <EOL> self . v . _table . can_refresh = True <EOL> self . v . _table . _rpc_get = MagicMock ( ) <EOL> self . v . refresh ( ) <EOL> self . v . _table . _rpc_get . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_view___getattr__wrong_attr ( self ) : <EOL> try : <EOL> self . v . abc <EOL> except Exception as ex : <EOL> self . assertEqual ( ex . __class__ , ValueError ) <EOL> def test_view_updater_context ( self ) : <EOL> with self . v . updater ( fields = False ) as up : <EOL> self . assertEqual ( up . __class__ . __name__ , '<STR_LIT>' ) <EOL> def test_view_updater_fields_true ( self ) : <EOL> def fn ( ) : <EOL> with self . v . updater ( fields = True ) : <EOL> pass <EOL> fn ( ) <EOL> self . assertEqual ( <EOL> self . v . GROUPS , { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_view_updater_groups_true ( self ) : <EOL> def fn ( ) : <EOL> with self . v . updater ( groups = True ) : <EOL> pass <EOL> fn ( ) <EOL> self . assertEqual ( <EOL> self . v . GROUPS , { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_view_updater_all_false ( self ) : <EOL> with self . v . updater ( all = False ) : <EOL> self . assertEqual ( <EOL> self . v . GROUPS , { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_view_updater_with_groups_all_true ( self ) : <EOL> def fn ( ) : <EOL> with self . v . updater ( all = True ) as more : <EOL> more . groups = { } <EOL> fn ( ) <EOL> self . assertEqual ( <EOL> self . v . GROUPS , { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_view_updater_with_groups_all_false ( self ) : <EOL> def fn ( ) : <EOL> with self . v . updater ( all = False ) as more : <EOL> more . groups = { } <EOL> fn ( ) <EOL> self . assertEqual ( <EOL> self . v . GROUPS , { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_view___getattr__table_item ( self ) : <EOL> tbl = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : PhyPortStatsTable } } <EOL> self . v . FIELDS . update ( tbl ) <EOL> self . assertEqual ( self . v . RouteTable . __class__ . __name__ , <EOL> '<STR_LIT>' ) <EOL> def test_view___getattr___munch ( self ) : <EOL> ret_val = '<STR_LIT>' <EOL> xml = etree . fromstring ( ret_val ) <EOL> self . v = PhyPortStatsView ( self . ppt , xml ) <EOL> tbl = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . v . FIELDS . update ( tbl ) <EOL> self . assertEqual ( self . v . RouteTable , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_view___getattr___munch_tag ( self ) : <EOL> ret_val = '<STR_LIT>' <EOL> xml = etree . fromstring ( ret_val ) <EOL> self . v = PhyPortStatsView ( self . ppt , xml ) <EOL> tbl = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } } <EOL> self . v . FIELDS . update ( tbl ) <EOL> self . assertEqual ( self . v . RouteTable , '<STR_LIT>' ) <EOL> def test_view___getattr___raise_RuntimeError ( self ) : <EOL> ret_val = '<STR_LIT>' <EOL> xml = etree . fromstring ( ret_val ) <EOL> self . v = PhyPortStatsView ( self . ppt , xml ) <EOL> tbl = { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:abc>' } } <EOL> self . v . FIELDS . update ( tbl ) <EOL> def fn ( ) : <EOL> return self . v . RouteTable <EOL> self . assertRaises ( RuntimeError , fn ) </s>
