<s> import json <EOL> from datetime import datetime <EOL> from twisted . trial . unittest import TestCase <EOL> from twisted . internet import defer <EOL> from twisted_web_test_utils import DummySite <EOL> from jasmin . protocols . http . configs import HTTPApiConfig <EOL> from jasmin . protocols . http . server import HTTPApi <EOL> from jasmin . protocols . http . stats import HttpAPIStatsCollector <EOL> from jasmin . routing . router import RouterPB <EOL> from jasmin . routing . configs import RouterPBConfig <EOL> from jasmin . managers . clients import SMPPClientManagerPB <EOL> from jasmin . managers . configs import SMPPClientPBConfig <EOL> from jasmin . routing . jasminApi import User , Group , SmppClientConnector <EOL> from jasmin . routing . Filters import UserFilter , GroupFilter <EOL> from jasmin . routing . Routes import DefaultRoute , StaticMTRoute <EOL> class HTTPApiTestCases ( TestCase ) : <EOL> def setUp ( self ) : <EOL> RouterPBConfigInstance = RouterPBConfig ( ) <EOL> self . RouterPB_f = RouterPB ( ) <EOL> self . RouterPB_f . setConfig ( RouterPBConfigInstance ) <EOL> self . g1 = Group ( <NUM_LIT:1> ) <EOL> self . u1 = User ( <NUM_LIT:1> , self . g1 , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . RouterPB_f . groups . append ( self . g1 ) <EOL> self . RouterPB_f . users . append ( self . u1 ) <EOL> self . RouterPB_f . mt_routing_table . add ( DefaultRoute ( SmppClientConnector ( '<STR_LIT:abc>' ) ) , <NUM_LIT:0> ) <EOL> SMPPClientPBConfigInstance = SMPPClientPBConfig ( ) <EOL> SMPPClientPBConfigInstance . authentication = False <EOL> clientManager_f = SMPPClientManagerPB ( ) <EOL> clientManager_f . setConfig ( SMPPClientPBConfigInstance ) <EOL> httpApiConfigInstance = HTTPApiConfig ( ) <EOL> self . web = DummySite ( HTTPApi ( self . RouterPB_f , clientManager_f , httpApiConfigInstance ) ) <EOL> def tearDown ( self ) : <EOL> self . RouterPB_f . cancelPersistenceTimer ( ) <EOL> class PingTestCases ( HTTPApiTestCases ) : <EOL> @ defer . inlineCallbacks <EOL> def test_basic_ping ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> class AuthenticationTestCases ( HTTPApiTestCases ) : <EOL> @ defer . inlineCallbacks <EOL> def test_send_normal ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertNotEqual ( response . value ( ) , "<STR_LIT>" % self . u1 . username ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_normal ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_normal ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_disabled_user ( self ) : <EOL> self . u1 . disable ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" % self . u1 . username ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_disabled_user ( self ) : <EOL> self . u1 . disable ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_disabled_user ( self ) : <EOL> self . u1 . disable ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_disabled_group ( self ) : <EOL> self . g1 . disable ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" % self . u1 . username ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_disabled_group ( self ) : <EOL> self . g1 . disable ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_disabled_group ( self ) : <EOL> self . g1 . disable ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . u1 . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' ) <EOL> class SendTestCases ( HTTPApiTestCases ) : <EOL> username = '<STR_LIT>' <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_correct_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" % self . username ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_incorrect_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_auth_success ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_priority ( self ) : <EOL> params = { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } <EOL> valid_priorities = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> } <EOL> for params [ '<STR_LIT>' ] in valid_priorities : <EOL> response = yield self . web . get ( "<STR_LIT>" , params ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> invalid_priorities = { - <NUM_LIT:1> , '<STR_LIT:a>' , <NUM_LIT> , <NUM_LIT:4> } <EOL> for params [ '<STR_LIT>' ] in invalid_priorities : <EOL> response = yield self . web . get ( "<STR_LIT>" , params ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' % params [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_validity_period ( self ) : <EOL> params = { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } <EOL> valid_vps = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT> } <EOL> for params [ '<STR_LIT>' ] in valid_vps : <EOL> response = yield self . web . get ( "<STR_LIT>" , params ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> invalid_vps = { - <NUM_LIT:1> , '<STR_LIT:a>' , <NUM_LIT:1.0> } <EOL> for params [ '<STR_LIT>' ] in invalid_vps : <EOL> response = yield self . web . get ( "<STR_LIT>" , params ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , '<STR_LIT>' % params [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_inurl_dlr ( self ) : <EOL> params = { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } <EOL> valid_urls = { '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' } <EOL> import time <EOL> for params [ '<STR_LIT>' ] in valid_urls : <EOL> response = yield self . web . get ( "<STR_LIT>" , params ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> invalid_urls = { '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' } <EOL> for params [ '<STR_LIT>' ] in invalid_urls : <EOL> response = yield self . web . get ( "<STR_LIT>" , params ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" % params [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_without_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_some_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . username } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) [ : <NUM_LIT> ] , "<STR_LIT>" ) <EOL> class RateTestCases ( HTTPApiTestCases ) : <EOL> def setUp ( self ) : <EOL> HTTPApiTestCases . setUp ( self ) <EOL> u2 = User ( <NUM_LIT:2> , Group ( <NUM_LIT:2> ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> u3 = User ( <NUM_LIT:3> , Group ( <NUM_LIT:2> ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> u3 . mt_credential . setQuota ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . RouterPB_f . users . append ( u2 ) <EOL> self . RouterPB_f . users . append ( u3 ) <EOL> filters = [ GroupFilter ( Group ( <NUM_LIT:2> ) ) ] <EOL> route = StaticMTRoute ( filters , SmppClientConnector ( '<STR_LIT:abc>' ) , <NUM_LIT> ) <EOL> self . RouterPB_f . mt_routing_table . add ( route , <NUM_LIT:2> ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_with_correct_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , u'<STR_LIT>' % '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_with_incorrect_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT:hello>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , u'<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_with_auth_success ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT:1> , u'<STR_LIT>' : <NUM_LIT:0.0> } ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_rated_route_unlimited_balance ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT:1> , u'<STR_LIT>' : <NUM_LIT:0.0> } ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_rated_route_unlimited_balance_long_content ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT:2> , u'<STR_LIT>' : <NUM_LIT:0.0> } ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_rated_route_defined_balance ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT:1> , u'<STR_LIT>' : <NUM_LIT> } ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_rated_route_defined_balance_long_content ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT:2> , u'<STR_LIT>' : <NUM_LIT> } ) <EOL> class BalanceTestCases ( HTTPApiTestCases ) : <EOL> def setUp ( self ) : <EOL> HTTPApiTestCases . setUp ( self ) <EOL> u2 = User ( <NUM_LIT:2> , Group ( <NUM_LIT:2> ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> u2 . mt_credential . setQuota ( '<STR_LIT>' , <NUM_LIT> ) <EOL> u2 . mt_credential . setQuota ( '<STR_LIT>' , <NUM_LIT:30> ) <EOL> u3 = User ( <NUM_LIT:3> , Group ( <NUM_LIT:2> ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> u3 . mt_credential . setQuota ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> self . RouterPB_f . users . append ( u2 ) <EOL> self . RouterPB_f . users . append ( u3 ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_with_correct_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , u'<STR_LIT>' % '<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_with_incorrect_args ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , u'<STR_LIT>' ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_with_auth_success_unlimited_quotas ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : u'<STR_LIT>' , u'<STR_LIT>' : u'<STR_LIT>' } ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_with_auth_success_defined_quotas_u2 ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT> , u'<STR_LIT>' : <NUM_LIT:30> } ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_with_auth_success_defined_quotas_u3 ( self ) : <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( json . loads ( response . value ( ) ) , { u'<STR_LIT>' : <NUM_LIT:10> , u'<STR_LIT>' : u'<STR_LIT>' } ) <EOL> class UserStatsTestCases ( HTTPApiTestCases ) : <EOL> username = '<STR_LIT>' <EOL> @ defer . inlineCallbacks <EOL> def test_send_failure ( self ) : <EOL> _submit_sm_request_count = self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertNotEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( _submit_sm_request_count + <NUM_LIT:0> , self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_success ( self ) : <EOL> _submit_sm_request_count = self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( _submit_sm_request_count + <NUM_LIT:1> , self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_failure ( self ) : <EOL> _balance_request_count = self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertNotEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( _balance_request_count + <NUM_LIT:0> , self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_balance_success ( self ) : <EOL> _balance_request_count = self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( _balance_request_count + <NUM_LIT:1> , self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_failure ( self ) : <EOL> _rate_request_count = self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertNotEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( _rate_request_count + <NUM_LIT:0> , self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> @ defer . inlineCallbacks <EOL> def test_rate_success ( self ) : <EOL> _rate_request_count = self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT:200> ) <EOL> self . assertEqual ( _rate_request_count + <NUM_LIT:1> , self . RouterPB_f . getUser ( <NUM_LIT:1> ) . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> class StatsTestCases ( HTTPApiTestCases ) : <EOL> username = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> HTTPApiTestCases . setUp ( self ) <EOL> created_at = HttpAPIStatsCollector ( ) . get ( ) . get ( '<STR_LIT>' ) <EOL> HttpAPIStatsCollector ( ) . get ( ) . init ( ) <EOL> HttpAPIStatsCollector ( ) . get ( ) . set ( '<STR_LIT>' , created_at ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_auth_failure ( self ) : <EOL> stats = HttpAPIStatsCollector ( ) . get ( ) <EOL> self . assertTrue ( type ( stats . get ( '<STR_LIT>' ) ) == datetime ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" % self . username ) <EOL> self . assertTrue ( type ( stats . get ( '<STR_LIT>' ) ) == datetime ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( type ( stats . get ( '<STR_LIT>' ) ) == datetime ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> @ defer . inlineCallbacks <EOL> def test_send_with_auth_success ( self ) : <EOL> stats = HttpAPIStatsCollector ( ) . get ( ) <EOL> response = yield self . web . get ( "<STR_LIT>" , { '<STR_LIT:username>' : self . username , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:to>' : '<STR_LIT>' , <EOL> '<STR_LIT:content>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . responseCode , <NUM_LIT> ) <EOL> self . assertEqual ( response . value ( ) , "<STR_LIT>" ) <EOL> self . assertTrue ( type ( stats . get ( '<STR_LIT>' ) ) == datetime ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( type ( stats . get ( '<STR_LIT>' ) ) == datetime ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( stats . get ( '<STR_LIT>' ) , <NUM_LIT:0> ) </s>
