<s> import sys <EOL> import os <EOL> import unittest <EOL> sys . path . append ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> from random import choice <EOL> from testlib import get_fixture , function , random_int , random_string <EOL> from testlib import EapiConfigUnitTest <EOL> import pyeapi . api . staticroute <EOL> IP_DESTS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> NEXT_HOPS = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None ) , ( '<STR_LIT>' , None ) ] <EOL> DISTANCES = TAGS = ROUTE_NAMES = [ None , True ] <EOL> class TestApiStaticroute ( EapiConfigUnitTest ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( TestApiStaticroute , self ) . __init__ ( * args , ** kwargs ) <EOL> self . instance = pyeapi . api . staticroute . StaticRoute ( None ) <EOL> self . config = open ( get_fixture ( '<STR_LIT>' ) ) . read ( ) <EOL> def test_instance ( self ) : <EOL> result = pyeapi . api . staticroute . instance ( None ) <EOL> self . assertIsInstance ( result , pyeapi . api . staticroute . StaticRoute ) <EOL> def test_get ( self ) : <EOL> ip_dest = '<STR_LIT>' <EOL> routes = { <EOL> '<STR_LIT>' : { <EOL> None : { <EOL> <NUM_LIT:1> : { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> } <EOL> } <EOL> } <EOL> } <EOL> result = self . instance . get ( ip_dest ) <EOL> self . assertEqual ( result , routes ) <EOL> ip_dest = '<STR_LIT>' <EOL> routes = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> <NUM_LIT:1> : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } , <EOL> <NUM_LIT:10> : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> <NUM_LIT:20> : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> } <EOL> } <EOL> } <EOL> result = self . instance . get ( ip_dest ) <EOL> self . assertEqual ( result , routes ) <EOL> def test_getall ( self ) : <EOL> routes = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> None : { <EOL> <NUM_LIT:1> : { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:0> } <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> <NUM_LIT:1> : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } , <EOL> <NUM_LIT:10> : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> <NUM_LIT:20> : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> self . maxDiff = None <EOL> result = self . instance . getall ( ) <EOL> self . assertEqual ( result , routes ) <EOL> def test_create ( self ) : <EOL> for ip_dest in IP_DESTS : <EOL> ( next_hop , next_hop_ip ) = choice ( NEXT_HOPS ) <EOL> distance = choice ( DISTANCES ) <EOL> if distance : <EOL> distance = random_int ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> tag = choice ( TAGS ) <EOL> if tag : <EOL> tag = random_int ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> route_name = choice ( ROUTE_NAMES ) <EOL> if route_name : <EOL> route_name = random_string ( minchar = <NUM_LIT:4> , maxchar = <NUM_LIT:10> ) <EOL> func = function ( '<STR_LIT>' , ip_dest , next_hop , <EOL> next_hop_ip = next_hop_ip , <EOL> distance = distance , <EOL> tag = tag , <EOL> route_name = route_name ) <EOL> cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = '<STR_LIT>' <EOL> if next_hop_ip is not None : <EOL> cmd_next_hop_ip = "<STR_LIT>" % next_hop_ip <EOL> if distance is not None : <EOL> cmd_distance = "<STR_LIT>" % distance <EOL> if tag is not None : <EOL> cmd_tag = "<STR_LIT>" % tag <EOL> if route_name is not None : <EOL> cmd_route_name = "<STR_LIT>" % route_name <EOL> cmds = "<STR_LIT>" % ( ip_dest , next_hop , cmd_next_hop_ip , cmd_distance , <EOL> cmd_tag , cmd_route_name ) <EOL> self . eapi_positive_config_test ( func , cmds ) <EOL> def test_delete ( self ) : <EOL> for ip_dest in IP_DESTS : <EOL> ( next_hop , next_hop_ip ) = choice ( NEXT_HOPS ) <EOL> distance = choice ( DISTANCES ) <EOL> if distance : <EOL> distance = random_int ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> tag = choice ( TAGS ) <EOL> if tag : <EOL> tag = random_int ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> route_name = choice ( ROUTE_NAMES ) <EOL> if route_name : <EOL> route_name = random_string ( minchar = <NUM_LIT:4> , maxchar = <NUM_LIT:10> ) <EOL> func = function ( '<STR_LIT>' , ip_dest , next_hop , <EOL> next_hop_ip = next_hop_ip , <EOL> distance = distance , <EOL> tag = tag , <EOL> route_name = route_name ) <EOL> cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = '<STR_LIT>' <EOL> if next_hop_ip is not None : <EOL> cmd_next_hop_ip = "<STR_LIT>" % next_hop_ip <EOL> if distance is not None : <EOL> cmd_distance = "<STR_LIT>" % distance <EOL> if tag is not None : <EOL> cmd_tag = "<STR_LIT>" % tag <EOL> if route_name is not None : <EOL> cmd_route_name = "<STR_LIT>" % route_name <EOL> cmds = "<STR_LIT>" % ( ip_dest , next_hop , cmd_next_hop_ip , cmd_distance , <EOL> cmd_tag , cmd_route_name ) <EOL> self . eapi_positive_config_test ( func , cmds ) <EOL> def test_default ( self ) : <EOL> for ip_dest in IP_DESTS : <EOL> ( next_hop , next_hop_ip ) = choice ( NEXT_HOPS ) <EOL> distance = choice ( DISTANCES ) <EOL> if distance : <EOL> distance = random_int ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> tag = choice ( TAGS ) <EOL> if tag : <EOL> tag = random_int ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> route_name = choice ( ROUTE_NAMES ) <EOL> if route_name : <EOL> route_name = random_string ( minchar = <NUM_LIT:4> , maxchar = <NUM_LIT:10> ) <EOL> func = function ( '<STR_LIT:default>' , ip_dest , next_hop , <EOL> next_hop_ip = next_hop_ip , <EOL> distance = distance , <EOL> tag = tag , <EOL> route_name = route_name ) <EOL> cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = '<STR_LIT>' <EOL> if next_hop_ip is not None : <EOL> cmd_next_hop_ip = "<STR_LIT>" % next_hop_ip <EOL> if distance is not None : <EOL> cmd_distance = "<STR_LIT>" % distance <EOL> if tag is not None : <EOL> cmd_tag = "<STR_LIT>" % tag <EOL> if route_name is not None : <EOL> cmd_route_name = "<STR_LIT>" % route_name <EOL> cmds = "<STR_LIT>" % ( ip_dest , next_hop , cmd_next_hop_ip , cmd_distance , <EOL> cmd_tag , cmd_route_name ) <EOL> self . eapi_positive_config_test ( func , cmds ) <EOL> def test_set_tag ( self ) : <EOL> ip_dest = '<STR_LIT>' <EOL> next_hop = '<STR_LIT>' <EOL> next_hop_ip = '<STR_LIT>' <EOL> distance = <NUM_LIT:10> <EOL> tag = '<STR_LIT>' <EOL> func = function ( '<STR_LIT>' , ip_dest , next_hop , <EOL> next_hop_ip = next_hop_ip , <EOL> distance = distance , tag = tag ) <EOL> cmd = "<STR_LIT>" % ( ip_dest , next_hop , next_hop_ip , distance , tag ) <EOL> self . eapi_positive_config_test ( func , cmd ) <EOL> def test_set_route_name ( self ) : <EOL> ip_dest = '<STR_LIT>' <EOL> next_hop = '<STR_LIT>' <EOL> next_hop_ip = '<STR_LIT>' <EOL> distance = <NUM_LIT:10> <EOL> route_name = '<STR_LIT>' <EOL> func = function ( '<STR_LIT>' , ip_dest , next_hop , <EOL> next_hop_ip = next_hop_ip , <EOL> distance = distance , route_name = route_name ) <EOL> cmd = "<STR_LIT>" % ( ip_dest , next_hop , next_hop_ip , distance , route_name ) <EOL> self . eapi_positive_config_test ( func , cmd ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
