#NEWLINE# def test_add_EvalPyFilter_withCode( self ) : #NEWLINE# #INDENT# pyCodeFile = 'pyCode.py' #NEWLINE# pyCode = "# Will filter all messages having 'hello world' in their content\nif routable.pdu.params['short_message'] == 'hello world':\n    result = True\nelse:\n    result = False\n" #NEWLINE# with open ( pyCodeFile , 'w' ) as f : #NEWLINE# #INDENT# f . write ( pyCode ) #NEWLINE# #UNINDENT# ftype = 'EvalPyFilter' #NEWLINE# _str_ = [ ( '%s:' % ftype ) ] #NEWLINE# _str_ . extend ( [ y for y in ( re . escape ( x . strip ( ) ) for x in pyCode . splitlines ( ) ) if y ] ) #NEWLINE# _repr_ = ( '<Ev \\(pyCode=%s ..\\)>' % pyCode [ : 10 ] . replace ( '\n' , '' ) ) #NEWLINE# extraCommands = [ { #NEWLINE# #INDENT# 'command' : 'fid filter_id' , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'command' : ( 'type %s' % ftype ) , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'command' : ( 'pyCode %s' % pyCodeFile ) , #NEWLINE# #UNINDENT# } ] #NEWLINE# self . add_filter ( 'jcli : ' , extraCommands ) #NEWLINE# expectedList = _str_ #NEWLINE# self . _test ( 'jcli : ' , [ { #NEWLINE# #INDENT# 'command' : 'filter -s filter_id' , #NEWLINE# 'expect' : expectedList , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# expectedList = [ '#Filter id        Type                   Routes Description' , ( '#filter_id        %s           MO MT  %s' % ( ftype , _repr_ ) ) , 'Total Filters: 1' ] #NEWLINE# self . _test ( 'jcli : ' , [ { #NEWLINE# #INDENT# 'command' : 'filter -l' , #NEWLINE# 'expect' : expectedList , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# unlink ( pyCodeFile )