<s> from twisted . trial . unittest import TestCase <EOL> from jasmin . routing . Interceptors import * <EOL> from jasmin . routing . Filters import * <EOL> from jasmin . routing . Routables import RoutableSubmitSm , RoutableDeliverSm <EOL> from jasmin . vendor . smpp . pdu . operations import SubmitSM , DeliverSM <EOL> class InterceptorTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . connector1 = Connector ( '<STR_LIT:abc>' ) <EOL> self . connector2 = Connector ( '<STR_LIT>' ) <EOL> self . script1 = InterceptorScript ( "<STR_LIT>" ) <EOL> self . group100 = Group ( <NUM_LIT:100> ) <EOL> self . user1 = User ( <NUM_LIT:1> , self . group100 , '<STR_LIT:username>' , '<STR_LIT:password>' ) <EOL> self . user2 = User ( <NUM_LIT:2> , self . group100 , '<STR_LIT:username>' , '<STR_LIT:password>' ) <EOL> self . invalid_filter = [ ConnectorFilter ( self . connector1 ) , UserFilter ( self . user1 ) ] <EOL> self . simple_filter_mo = [ ConnectorFilter ( self . connector1 ) ] <EOL> self . simple_filter_mt = [ UserFilter ( self . user1 ) ] <EOL> self . simple_filter_all = [ DestinationAddrFilter ( r'<STR_LIT>' ) ] <EOL> class InterceptorStrTestCase ( InterceptorTestCase ) : <EOL> def test_StaticMTInterceptor ( self ) : <EOL> s = StaticMTInterceptor ( self . simple_filter_mt , self . script1 ) <EOL> self . assertEqual ( str ( s ) , '<STR_LIT>' ) <EOL> def test_StaticMOInterceptor ( self ) : <EOL> s = StaticMOInterceptor ( self . simple_filter_mo , self . script1 ) <EOL> self . assertEqual ( str ( s ) , '<STR_LIT>' ) <EOL> def test_DefaultInterceptor ( self ) : <EOL> s = DefaultInterceptor ( self . script1 ) <EOL> self . assertEqual ( str ( s ) , '<STR_LIT>' ) <EOL> class AnyStaticInterceptorTestCase ( InterceptorTestCase ) : <EOL> def test_standard ( self ) : <EOL> StaticMTInterceptor ( self . simple_filter_mt , self . script1 ) <EOL> StaticMOInterceptor ( self . simple_filter_mo , self . script1 ) <EOL> def test_parameters ( self ) : <EOL> self . assertRaises ( InvalidInterceptorParameterError , <EOL> StaticMTInterceptor , '<STR_LIT>' , self . script1 ) <EOL> self . assertRaises ( InvalidInterceptorParameterError , <EOL> StaticMTInterceptor , [ '<STR_LIT>' ] , self . script1 ) <EOL> self . assertRaises ( InvalidInterceptorParameterError , <EOL> StaticMTInterceptor , self . simple_filter_mt , '<STR_LIT>' ) <EOL> def test_filter_type_compatibility ( self ) : <EOL> self . assertRaises ( InvalidInterceptorFilterError , <EOL> StaticMTInterceptor , self . invalid_filter , self . script1 ) <EOL> self . assertRaises ( InvalidInterceptorFilterError , <EOL> StaticMOInterceptor , self . simple_filter_mt , self . script1 ) <EOL> self . assertRaises ( InvalidInterceptorFilterError , <EOL> StaticMTInterceptor , self . simple_filter_mo , self . script1 ) <EOL> class DefaultInterceptorTestCase ( InterceptorTestCase ) : <EOL> def setUp ( self ) : <EOL> InterceptorTestCase . setUp ( self ) <EOL> self . PDU_dst_1 = SubmitSM ( <EOL> source_addr = '<STR_LIT>' , <EOL> destination_addr = '<STR_LIT:1>' , <EOL> short_message = '<STR_LIT>' , <EOL> ) <EOL> self . routable_user1 = RoutableSubmitSm ( self . PDU_dst_1 , self . user1 ) <EOL> def test_standard ( self ) : <EOL> o = DefaultInterceptor ( self . script1 ) <EOL> t = o . matchFilters ( self . routable_user1 ) <EOL> self . assertNotEqual ( t , None ) <EOL> self . assertEqual ( t , self . script1 ) <EOL> class StaticMTInterceptorTestCase ( InterceptorTestCase ) : <EOL> def setUp ( self ) : <EOL> InterceptorTestCase . setUp ( self ) <EOL> self . PDU_dst_1 = SubmitSM ( <EOL> source_addr = '<STR_LIT>' , <EOL> destination_addr = '<STR_LIT:1>' , <EOL> short_message = '<STR_LIT>' , <EOL> ) <EOL> self . routable_user1 = RoutableSubmitSm ( self . PDU_dst_1 , self . user1 ) <EOL> self . routable_user2 = RoutableSubmitSm ( self . PDU_dst_1 , self . user2 ) <EOL> def test_standard ( self ) : <EOL> o = StaticMTInterceptor ( self . simple_filter_mt , self . script1 ) <EOL> t = o . matchFilters ( self . routable_user1 ) <EOL> self . assertNotEqual ( t , None ) <EOL> self . assertEqual ( t , self . script1 ) <EOL> t = o . matchFilters ( self . routable_user2 ) <EOL> self . assertEqual ( t , None ) <EOL> class StaticMOInterceptorTestCase ( InterceptorTestCase ) : <EOL> def setUp ( self ) : <EOL> InterceptorTestCase . setUp ( self ) <EOL> self . PDU_dst_1 = DeliverSM ( <EOL> source_addr = '<STR_LIT>' , <EOL> destination_addr = '<STR_LIT:1>' , <EOL> short_message = '<STR_LIT>' , <EOL> ) <EOL> self . routable_connector1 = RoutableDeliverSm ( self . PDU_dst_1 , self . connector1 ) <EOL> self . routable_connector2 = RoutableDeliverSm ( self . PDU_dst_1 , self . connector2 ) <EOL> def test_standard ( self ) : <EOL> o = StaticMOInterceptor ( self . simple_filter_mo , self . script1 ) <EOL> t = o . matchFilters ( self . routable_connector1 ) <EOL> self . assertNotEqual ( t , None ) <EOL> self . assertEqual ( t , self . script1 ) <EOL> t = o . matchFilters ( self . routable_connector2 ) <EOL> self . assertEqual ( t , None ) </s>
