def test_default(self): b = SubmitSmBill(self.user) self.assertEqual(b.getAmount('submit_sm'), 0.0) self.assertEqual(b.getAmount('submit_sm_resp'), 0.0) self.assertEqual(b.getAction('decrement_submit_sm_count'), 0) self.assertNotEquals(b.bid, None) self.assertEqual(b.user, self.user)
def test_amounts(self): b = SubmitSmBill(self.user) b.setAmount('submit_sm', 1.1) b.setAmount('submit_sm_resp', 2) self.assertEqual(b.getAmount('submit_sm'), 1.1) self.assertEqual(b.getAmount('submit_sm_resp'), 2) self.assertEqual(b.getTotalAmounts(), 3.1)
def setUp(self): yield SMSCSimulatorRecorder.setUp(self) self.SMSCPort.factory.buildProtocol = mock.Mock( wraps=self.SMSCPort.factory.buildProtocol) self.SubmitSmBill = SubmitSmBill( User('test_user', Group('test_group'), 'test_username', 'pwd'))
def test_typing(self): b = SubmitSmBill(self.user) self.assertRaises(InvalidBillKeyError, b.getAmount, 'anyKey') self.assertRaises(InvalidBillKeyError, b.getAction, 'anyKey') self.assertRaises(InvalidBillKeyError, b.setAmount, 'anyKey', 0) self.assertRaises(InvalidBillKeyError, b.setAction, 'anyKey', 0) self.assertRaises(InvalidBillValueError, b.setAction, 'decrement_submit_sm_count', 1.1) self.assertRaises(InvalidBillValueError, b.setAmount, 'submit_sm', '1.1') self.assertRaises(InvalidBillValueError, b.setAmount, 'submit_sm_resp', 'A')
def setUp(self): yield SMSCSimulatorRecorder.setUp(self) self.SMSCPort.factory.buildProtocol = mock.Mock(wraps=self.SMSCPort.factory.buildProtocol) config = SMPPClientConfig(id='defaultId') opFactory = SMPPOperationFactory(config) self.SubmitSmPDU = opFactory.SubmitSM( source_addr='1423', destination_addr='06155423', short_message='Hello world !', ) self.SubmitSmBill = SubmitSmBill(User('test_user', Group('test_group'), 'test_username', 'pwd'))
def test_getSubmitSmRespBill(self): b = SubmitSmBill(self.user) b.setAmount('submit_sm', 1.1) b.setAmount('submit_sm_resp', 2) c = b.getSubmitSmRespBill() self.assertRaises(InvalidBillKeyError, c.getAmount, 'submit_sm') self.assertEqual(c.getAmount('submit_sm_resp'), 2.0) self.assertRaises(InvalidBillKeyError, c.getAction, 'decrement_submit_sm_count') self.assertNotEquals(c.bid, None) self.assertNotEquals(b.bid, c.bid) self.assertEqual(b.user, c.user)
def getBillFor(self, user): """This will return the exact bill for user depending on his defined quotas """ if not isinstance(user, User): raise InvalidRouteParameterError("user is not an instance of User") # Init bill = SubmitSmBill(user) # Route billing processing # [RULE 1] If route is rated and user's balance is not unlimited (balance != None) then # user will be billed for the selected route rate. if self.getRate() > 0 and user.mt_credential.getQuota( 'balance') is not None: early_decrement_balance_percent = user.mt_credential.getQuota( 'early_decrement_balance_percent') route_rate = self.getRate() # if early_decrement_balance_percent is defined then user will be: # - First: billed early_decrement_balance_percent % of the route rate on submit_sm # - Second: billed for the rest of the route rate on submit_sm_resp reception # If early_decrement_balance_percent is None (undefined) then the route rate will be # billed on submit_sm with no care about submit_sm_resp if early_decrement_balance_percent is not None: bill.setAmount( 'submit_sm', route_rate * early_decrement_balance_percent / 100) bill.setAmount('submit_sm_resp', route_rate - bill.getAmount('submit_sm')) else: bill.setAmount('submit_sm', route_rate) bill.setAmount('submit_sm_resp', 0) # [RULE 2] if user's submit_sm_count is not unlimited (!=None) then decrement it when sending # submit_sm if user.mt_credential.getQuota('submit_sm_count') is not None: bill.setAction('decrement_submit_sm_count', 1) return bill
def getBillFor(self, user): """This will return the exact bill for user depending on his defined quotas """ if not isinstance(user, User): raise InvalidRouteParameterError("user is not an instance of User") # Init bill = SubmitSmBill(user) # Route billing processing # [RULE 1] If route is rated and user's balance is not unlimited (balance != None) then # user will be billed for the selected route rate. if self.getRate() > 0 and user.mt_credential.getQuota('balance') is not None: early_decrement_balance_percent = user.mt_credential.getQuota('early_decrement_balance_percent') route_rate = self.getRate() # if early_decrement_balance_percent is defined then user will be: # - First: billed early_decrement_balance_percent % of the route rate on submit_sm # - Second: billed for the rest of the route rate on submit_sm_resp reception # If early_decrement_balance_percent is None (undefined) then the route rate will be # billed on submit_sm with no care about submit_sm_resp if early_decrement_balance_percent is not None: bill.setAmount('submit_sm', route_rate * early_decrement_balance_percent / 100) bill.setAmount('submit_sm_resp', route_rate - bill.getAmount('submit_sm')) else: bill.setAmount('submit_sm', route_rate) bill.setAmount('submit_sm_resp', 0) # [RULE 2] if user's submit_sm_count is not unlimited (!=None) then decrement it when sending # submit_sm if user.mt_credential.getQuota('submit_sm_count') is not None: bill.setAction('decrement_submit_sm_count', 1) return bill