#NEWLINE# def testRuleAdding( self ) : #NEWLINE# #INDENT# foreman = aff4 . FACTORY . Open ( 'aff4:/foreman' , mode = 'rw' , token = self . token ) #NEWLINE# rules = foreman . Get ( foreman . Schema . RULES ) #NEWLINE# self . assertEqual ( len ( rules ) , 0 ) #NEWLINE# hunt = hunts . GRRHunt . StartHunt ( hunt_name = 'SampleHunt' , regex_rules = [ rdf_foreman . ForemanAttributeRegex ( attribute_name = 'GRR client' , attribute_regex = 'HUNT' ) ] , integer_rules = [ rdf_foreman . ForemanAttributeInteger ( attribute_name = 'Clock' , operator = rdf_foreman . ForemanAttributeInteger . Operator . GREATER_THAN , value = 1336650631137737 ) ] , client_rate = 0 , token = self . token ) #NEWLINE# with hunt : #NEWLINE# #INDENT# hunt . GetRunner ( ) . Start ( ) #NEWLINE# #UNINDENT# foreman = aff4 . FACTORY . Open ( 'aff4:/foreman' , mode = 'rw' , token = self . token ) #NEWLINE# rules = foreman . Get ( foreman . Schema . RULES ) #NEWLINE# self . assertEqual ( len ( rules ) , 1 ) #NEWLINE# rule = rules [ 0 ] #NEWLINE# self . assertEqual ( len ( rule . regex_rules ) , 1 ) #NEWLINE# self . assertEqual ( rule . regex_rules [ 0 ] . attribute_name , 'GRR client' ) #NEWLINE# self . assertEqual ( rule . regex_rules [ 0 ] . attribute_regex , 'HUNT' ) #NEWLINE# self . assertEqual ( len ( rule . integer_rules ) , 1 ) #NEWLINE# self . assertEqual ( rule . integer_rules [ 0 ] . attribute_name , 'Clock' ) #NEWLINE# self . assertEqual ( rule . integer_rules [ 0 ] . operator , rdf_foreman . ForemanAttributeInteger . Operator . GREATER_THAN ) #NEWLINE# self . assertEqual ( rule . integer_rules [ 0 ] . value , 1336650631137737 ) #NEWLINE# self . assertEqual ( len ( rule . actions ) , 1 ) #NEWLINE# self . assertEqual ( rule . actions [ 0 ] . hunt_name , 'SampleHunt' ) #NEWLINE# with rules : #NEWLINE# #INDENT# hunt . GetRunner ( ) . Start ( ) #NEWLINE# #UNINDENT# foreman = aff4 . FACTORY . Open ( 'aff4:/foreman' , mode = 'rw' , token = self . token ) #NEWLINE# rules = foreman . Get ( foreman . Schema . RULES ) #NEWLINE# self . assertEqual ( len ( rules ) , 1 )