#NEWLINE# def test_children1( self ) : #NEWLINE# #INDENT# ' Add some prefixes and make sure number of children is correct\n        ' #NEWLINE# th = TestHelper ( ) #NEWLINE# p1 = th . add_prefix ( '192.168.0.0/16' , 'reservation' , 'test' ) #NEWLINE# p2 = th . add_prefix ( '192.168.0.0/20' , 'reservation' , 'test' ) #NEWLINE# p3 = th . add_prefix ( '192.168.0.0/24' , 'reservation' , 'test' ) #NEWLINE# p4 = th . add_prefix ( '192.168.1.0/24' , 'reservation' , 'test' ) #NEWLINE# p5 = th . add_prefix ( '192.168.2.0/24' , 'reservation' , 'test' ) #NEWLINE# p6 = th . add_prefix ( '192.168.32.0/20' , 'reservation' , 'test' ) #NEWLINE# p7 = th . add_prefix ( '192.168.32.0/24' , 'reservation' , 'test' ) #NEWLINE# expected = [ ] #NEWLINE# expected . append ( [ p1 . prefix , 2 ] ) #NEWLINE# expected . append ( [ p2 . prefix , 3 ] ) #NEWLINE# expected . append ( [ p3 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p4 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p5 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p2 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p7 . prefix , 0 ] ) #NEWLINE# res = Prefix . smart_search ( '0.0.0.0/0' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# result = [ ] #NEWLINE# for prefix in res [ 'result' ] : #NEWLINE# #INDENT# result . append ( [ prefix . prefix , prefix . children ] ) #NEWLINE# #UNINDENT# self . assertEqual ( expected , result ) #NEWLINE# p5 . prefix = '192.0.2.0/24' #NEWLINE# p5 . save ( ) #NEWLINE# expected = [ ] #NEWLINE# expected . append ( [ p5 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p1 . prefix , 2 ] ) #NEWLINE# expected . append ( [ p2 . prefix , 2 ] ) #NEWLINE# expected . append ( [ p3 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p4 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p6 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p7 . prefix , 0 ] ) #NEWLINE# res = Prefix . smart_search ( '0.0.0.0/0' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# result = [ ] #NEWLINE# for prefix in res [ 'result' ] : #NEWLINE# #INDENT# result . append ( [ prefix . prefix , prefix . children ] ) #NEWLINE# #UNINDENT# self . assertEqual ( expected , result ) #NEWLINE# p4 . prefix = '192.168.0.0/21' #NEWLINE# p4 . save ( ) #NEWLINE# expected = [ ] #NEWLINE# expected . append ( [ p5 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p1 . prefix , 2 ] ) #NEWLINE# expected . append ( [ p2 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p4 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p3 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p6 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p7 . prefix , 0 ] ) #NEWLINE# res = Prefix . smart_search ( '0.0.0.0/0' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# result = [ ] #NEWLINE# for prefix in res [ 'result' ] : #NEWLINE# #INDENT# result . append ( [ prefix . prefix , prefix . children ] ) #NEWLINE# #UNINDENT# self . assertEqual ( expected , result ) #NEWLINE# p1 . remove ( ) #NEWLINE# expected = [ ] #NEWLINE# expected . append ( [ p5 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p2 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p4 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p3 . prefix , 0 ] ) #NEWLINE# expected . append ( [ p6 . prefix , 1 ] ) #NEWLINE# expected . append ( [ p7 . prefix , 0 ] ) #NEWLINE# res = Prefix . smart_search ( '0.0.0.0/0' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# result = [ ] #NEWLINE# for prefix in res [ 'result' ] : #NEWLINE# #INDENT# result . append ( [ prefix . prefix , prefix . children ] ) #NEWLINE# #UNINDENT# self . assertEqual ( expected , result )