@@ -1245,10 +1245,112 @@ def _setup(self):
12451245 )
12461246 )
12471247 params .append (Base .VersionedParamPath ("someint" , path = "someint" , vartype = "int" ))
1248+ params .append (
1249+ Base .VersionedParamPath ("base_uuid" , path = "uuid" , vartype = "attrib" )
1250+ )
1251+ params .append (Base .VersionedParamPath ("action" , path = "config/action" ))
1252+ params .append (
1253+ Base .VersionedParamPath (
1254+ "action_uuid" , path = "config/action/uuid" , vartype = "attrib"
1255+ )
1256+ )
12481257
12491258 self ._params = tuple (params )
12501259
12511260
1261+ class TestVariableRefreshes (unittest .TestCase ):
1262+ def obj (self , key , attribs , value ):
1263+ o = MyVersionedObject ("foo" )
1264+ o .xpath = mock .Mock (return_value = "/unit/test/xpath/for/entry[@name='foo']" )
1265+
1266+ av = ""
1267+ if attribs :
1268+ for k , v in attribs .items ():
1269+ av += ' {0}="{1}"' .format (k , v )
1270+ respString = "<response><result><{0}{1}>{2}</{0}></result></response>" .format (
1271+ key , av , value , key
1272+ )
1273+ resp = ET .fromstring (respString )
1274+
1275+ spec = {
1276+ "id" : "unittest" ,
1277+ "get_device_version.return_value" : o ._UNKNOWN_PANOS_VERSION ,
1278+ "xapi.show.return_value" : resp ,
1279+ "xapi.get.return_value" : resp ,
1280+ }
1281+ m = mock .Mock (** spec )
1282+
1283+ o .nearest_pandevice = mock .Mock (return_value = m )
1284+
1285+ return m , o
1286+
1287+ def test_entry_refresh (self ):
1288+ m , o = self .obj ("entries" , None , "<entry name='one'/><entry name='two'/>" )
1289+
1290+ ans = o .refresh_variable ("entries" )
1291+
1292+ m .xapi .get .assert_called_once_with (
1293+ o .xpath () + "/multiple/entries" , retry_on_peer = o .HA_SYNC ,
1294+ )
1295+ self .assertEqual (ans , o .entries )
1296+ self .assertEqual (ans , ["one" , "two" ])
1297+
1298+ def test_member_refresh (self ):
1299+ m , o = self .obj (
1300+ "members" , None , "<member>first</member><member>second</member>"
1301+ )
1302+
1303+ ans = o .refresh_variable ("members" )
1304+
1305+ m .xapi .get .assert_called_once_with (
1306+ o .xpath () + "/multiple/members" , retry_on_peer = o .HA_SYNC ,
1307+ )
1308+ self .assertEqual (ans , o .members )
1309+ self .assertEqual (ans , ["first" , "second" ])
1310+
1311+ def test_int_refresh (self ):
1312+ m , o = self .obj ("someint" , None , "42" )
1313+
1314+ ans = o .refresh_variable ("someint" )
1315+
1316+ m .xapi .get .assert_called_once_with (
1317+ o .xpath () + "/someint" , retry_on_peer = o .HA_SYNC ,
1318+ )
1319+ self .assertEqual (ans , o .someint )
1320+ self .assertEqual (ans , 42 )
1321+
1322+ def test_base_attrib_refresh (self ):
1323+ m , o = self .obj ("entry" , {"name" : "foo" , "uuid" : "1234-56-789" }, "" )
1324+
1325+ ans = o .refresh_variable ("base_uuid" )
1326+
1327+ m .xapi .get .assert_called_once_with (o .xpath (), retry_on_peer = o .HA_SYNC )
1328+ self .assertEqual (ans , o .base_uuid )
1329+ self .assertEqual (ans , "1234-56-789" )
1330+
1331+ def test_string_refresh (self ):
1332+ m , o = self .obj ("action" , {"uuid" : "1234-56-789" }, "DENY" )
1333+
1334+ ans = o .refresh_variable ("action" )
1335+
1336+ m .xapi .get .assert_called_once_with (
1337+ o .xpath () + "/config/action" , retry_on_peer = o .HA_SYNC ,
1338+ )
1339+ self .assertEqual (ans , o .action )
1340+ self .assertEqual (ans , "DENY" )
1341+
1342+ def test_nested_attrib_refresh (self ):
1343+ m , o = self .obj ("action" , {"uuid" : "1234-56-789" }, "DENY" )
1344+
1345+ ans = o .refresh_variable ("action_uuid" )
1346+
1347+ m .xapi .get .assert_called_once_with (
1348+ o .xpath () + "/config/action" , retry_on_peer = o .HA_SYNC ,
1349+ )
1350+ self .assertEqual (ans , o .action_uuid )
1351+ self .assertEqual (ans , "1234-56-789" )
1352+
1353+
12521354class TestEqual (unittest .TestCase ):
12531355 def test_ordered (self ):
12541356 o1 = MyVersionedObject ("a" , ["a" , "b" ], ["c" , "d" ], 5 )
0 commit comments