示例#1
0
文件: admin.py 项目: sridwan/meong
 def depmut_execute(self, agent_id, type, amount, comment, pin):
     result = {
       'success': 0,
       'balance': 0,
     }
     try:
         int(amount)
     except:
         result['message'] = 'AMOUNT NOT VALID'
         return json.dumps(result)
     # agent must exist
     bc = AgentNotifier()
     c_agent = DBCache(const.AGENT_PREFIX, config.DEFAULT_EXPIRE,
                       const.AGENT_SQL)
     c_agent.setConn(bc.dbconn, bc.cacheconn)
     #print c_agent.sGet(agentid)
     ag = c_agent.sGet(agent_id)
     if not ag:
         result['message'] = 'AGENT NOT REGISTERED'
         return json.dumps(result)
     dm = DepositMutation(20, bc.dbconn, bc.cacheconn)
     prev_bal = dm.getBalance(agent_id)
     if type.upper() == 'C':
         balance = dm.credit(agent_id, int(amount), comment)
         bc.writeNotifyOut(ag['default_protocol'], 'deposit_credit', {
                 'mutation': thousandSeparator(amount),
                 'balance_before': thousandSeparator(prev_bal),
                 'balance': thousandSeparator(balance),
             })
     elif type.upper() == 'D':
         balance = dm.debit(agent_id, int(amount), comment)
         bc.writeNotifyOut(ag['default_protocol'], 'deposit_debit', {
                 'mutation': thousandSeparator(amount),
                 'balance_before': thousandSeparator(prev_bal),
                 'balance': thousandSeparator(balance),
             })
     else:
         result['message'] = 'TYPE NOT RECOGNIZED'
         return json.dumps(result)
     if balance == NOT_ENOUGH_BALANCE:
         result['message'] = 'NOT ENOUGH BALANCE'
         return json.dumps(result)
     elif balance == LOCK_FAILED:
         result['message'] = 'SERVER BUSY'
         return json.dumps(result)
     bc.dbconn.commit()
     msg = '{0}-{1} Deposit: Rp. {2} Before: Rp. {3} After: Rp. {4} ({5}) ID:{6}'.\
           format(ag['agent_id'], ag['agent_name'], thousandSeparator(amount),
                  thousandSeparator(prev_bal), thousandSeparator(balance),
                  comment, dm.last_id)
     for prot in ('ym://b_martian','ym://inileonard', 'ym://sridwan981'):
         bc.writeNotifyOut(prot, 'general_message', {'message': msg})
     bc.dbconn.commit()
     result.update({
         'success': 1,
         'message': 'SUCCESS',
         'balance': balance,
         'mutation_id': dm.last_id,
     })
     return json.dumps(result)
示例#2
0
文件: admin.py 项目: sridwan/meong
 def transaction_fail(self, tran_id, pin):
     bc = AgentNotifier()
     c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor)
     c.execute('''SELECT SQL_NO_CACHE `reg_protocol`,`product_id`,`msisdn_destination`,
                 `agent_id`,`sell_price`,`status`,`order`,`deposit`,`type`
                 FROM `transaction` where `transaction_id`=%s''',
                 (tran_id,))
     r = c.fetchone()
     if not r:
         return json.dumps({'success': 0, 'reason': 'RECORD NOT FOUND'})
     if int(r['status']) < const.TR_AUTHORIZED or \
                 int(r['status']) >= const.TR_RETRIED:
         return json.dumps({'success': 0, 'reason': 'CANNOT SET STATUS'})
     dm = DepositMutation(20, bc.dbconn, bc.cacheconn)
     dm.credit(r['agent_id'], r['sell_price'], 'reversal Transaction {0}'.\
               format(tran_id))
     c.execute('UPDATE `transaction` set `status`=%s where `transaction_id`=%s',
               (const.TR_FAILED_GENERAL_REV, tran_id,))
     # r['deposit'] = int(r['deposit']) + int(r['sell_price'])
     bc.notifyTopupFail(r, False)
     bc.dbconn.commit()
     return json.dumps({'success': 1, 'reason': 'SUCCESS'})
示例#3
0
class TestDepositMutation(TestAdminHelper):
#----------------------
    def setUp(self):
        self.bc = BaseComponent()
        self.dbconn = self.bc.dbconn
        self.cacheconn = self.bc.cacheconn
        self.cacheconn.delete('{0}_00001'.format(const.MUTATION_PREFIX))
        cursor = self.dbconn.cursor()
        self._resetTable('Deposit_Mutation')
        try:
            cursor.execute('''INSERT INTO `agent` (`agent_id`, `active`, `agent_name`,
              `agent_address`, `agent_type`, `pin`, `upline_id`, `markup`,
              `markup_upline`, `set_price`, `register_date`, `last_activity_date`,
              `last_update`, `last_update_by`) VALUES
              ('00001', 1, 'Bernard Martian', 'Test', 1, '9999', '', 100, 0, 'Test',
              '2010-11-09 18:24:44', '2010-11-09 18:24:51', '2010-11-24 00:50:12', '')''')
        except:
            pass
        cursor.close()
        self.dbconn.commit()

        self.c_agent = DBCache(const.AGENT_PREFIX, config.DEFAULT_EXPIRE,
          const.AGENT_SQL)
        self.c_agent.setConn(self.dbconn, self.cacheconn)
        self.dm = DepositMutation(2, self.dbconn, self.cacheconn)
#----------------------
    def runTest(self):
        test_function = [x for x in dir(self) if x[:6] == 'srtest']
        map(lambda x: getattr(self, x)(), sorted(test_function))
#----------------------
    def srtest010(self):
        balance = self.dm.debit('00001', 10000, 'srtest010')
        self.dbconn.commit()
        self.assertEqual(balance, depmut.NOT_ENOUGH_BALANCE)
        balance = self.dm.credit('00001', 10000, 'srtest010')
        self.dbconn.commit()
        self.assertEqual(balance, 10000)
        balance = self.dm.debit('00001', 5000, 'srtest010')
        self.dbconn.commit()
        self.assertEqual(balance, 5000)
#----------------------
    def srtest020_lock(self):
        self.dm.l_mutation.lockNoWait(self.cacheconn, '00001')
        balance = self.dm.credit('00001', 10000, 'srtest010')
        self.assertEqual(balance, depmut.LOCK_FAILED)
        self.dm.l_mutation.release(self.cacheconn, '00001')
#----------------------
    def srtest030_adminHelperDepositMutation(self):
        post_data = {
          'agent_id': '00001',
          'type': 'D',
          'amount': 5000
        }
        tmp = self._callAdminHelper('deposit_mutation', post_data)
        self.assertEqual(tmp['success'], 1)
        self.assertEqual(tmp['balance'], 0)
        tmp = self._callAdminHelper('deposit_mutation', post_data)
        self.assertEqual(tmp['success'], 0)
        self.assertEqual(tmp['message'], 'NOT ENOUGH BALANCE')
        post_data['type'] = 'X'
        tmp = self._callAdminHelper('deposit_mutation', post_data)
        self.assertEqual(tmp['success'], 0)
        self.assertEqual(tmp['message'], 'TYPE NOT RECOGNIZED')
        post_data['agent_id'] = 'xxx'
        tmp = self._callAdminHelper('deposit_mutation', post_data)
        self.assertEqual(tmp['success'], 0)
        self.assertEqual(tmp['message'], 'AGENT NOT REGISTERED')
#----------------------
    def tearDown(self):
        self.cacheconn.delete('{0}_00001'.format(const.MUTATION_PREFIX))
        self.dbconn.close()
示例#4
0
class TestAuthorizer(TestCoreComponent):
    def setUp(self):
        super(TestAuthorizer, self).setUp()
        self.cacheconn.flush_all()
        cursor = self.dbconn.cursor()
        self._resetTable('Transaction')
        self._resetTable('Notify_Out')
        self._resetTable('Deposit_Mutation')
        cursor.execute('DELETE FROM `operator`')
        cursor.execute('''INSERT INTO `operator` (`operator_id`, `operator_name`, `type`, `prefix`, `stock_check_1`, `stock_check_2`, `sim_balance`, `last_update`, `last_update_by`) VALUES
          (1, 'Telkomsel', 'G', '0812,0813,0852,0853', 'ussd://*776*<pin>#', 'ussd://*676*<pin>#', 'ussd://*888#', '2010-11-17 17:34:44', ''),
          (2, 'Indosat', 'G', '0814,0815,0816,0855,0856,0857,0858', 'data://31.<pin>$', '', 'ussd://*388#', '2010-10-29 18:52:34', ''),
          (3, 'XL', 'G', '0817,0818,0819,0859,0877,0878', 'sms://balance,461', '', 'ussd://*123#', '2010-10-29 18:52:48', ''),
          (4, 'Three', 'G', '0894,0896,0898,0899', 'data://+13.<pin>$', '', '', '2010-10-20 15:08:41', ''),
          (5, 'Axis', 'G', '0831,0832,0833,0838', 'data://13.<pin>$', '', '', '2010-10-20 15:08:36', ''),
          (6, 'Fren', 'G', '0888,0889', '', '', '', '0000-00-00 00:00:00', ''),
          (7, 'Esia', 'C', '4,6,8,9', 'sms:// bal <pin>,898', '', 'sms://talktime,555', '2010-11-17 20:52:29', ''),
          (8, 'Flexi', 'C', '2,3,4,5,6,7,8,9', 'sms://qd#<pin,899', '', '', '2010-10-20 15:10:59', ''),
          (9, 'StarOne', 'C', '3,8', '', '', '', '0000-00-00 00:00:00', ''),
          (10, 'Hepi', 'C', '3,4,5', '', '', '', '0000-00-00 00:00:00', ''),
          (11, 'Smart', 'G', '0881,0882,0883,0884,0885,0886,0887', '', '', '', '0000-00-00 00:00:00', '')''')
        cursor.execute('DELETE FROM `agent_price`')
        cursor.execute('''INSERT INTO `agent_price` (`agent_id`, `product_id`,
          `sell_price`, `markup_upline`, `date_time`, `status`, `last_update`,
          `last_update_by`) VALUES
          ('00001', 'A10', 10150, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'A5', 5150, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'AP10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'AP5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'AX10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'AX20', 20100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'AX50', 50100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'E25', 25100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'E50', 50100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'F10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'F20', 20100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'F5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'FR10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'FR20', 20100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'FR25', 25100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'H10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'H25', 25100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'H5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'M10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'M5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'S10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'S5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SM10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SM20', 20100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SM5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SO10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SO20', 20100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SO5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SP10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'SP5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'T10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'T20', 20100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'T5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'X10', 10100, 0, NULL, 1, '0000-00-00 00:00:00', ''),
          ('00001', 'X5', 5100, 0, NULL, 1, '0000-00-00 00:00:00', '')''')
        cursor.execute('DELETE FROM `product`')
        cursor.execute('''INSERT INTO `product` (`product_id`, `product_name`, `operator_id`, `active`, `point`, `operator_product_id_1`, `operator_product_id_2`, `operator_product_id_3`, `operator_product_id_4`, `operator_product_id_5`, `method_1`, `method_1_active`, `method_2`, `method_2_active`, `method_3`, `method_3_active`, `method_4`, `method_4_active`, `method_5`, `method_5_active`, `last_update`, `last_update_by`) VALUES
          ('A10', 'As 10.000', 1, 1, 1, 'SIMPATI10', 'AS10', '', '', '', 'CH', 1, 'H2', 0, 'YM', 0, '', 0, '', 0, '2010-07-08 18:48:06', ''),
          ('A5', 'As 5.000', 1, 1, 1, 'SIMPATI5', 'AS5', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:07', ''),
          ('AP10', 'As 10.000 Promo', 1, 1, 1, 'AS5', 'SIMPATI5', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:08', ''),
          ('AP5', 'As 5.000 Promo', 1, 0, 1, 'AS5', 'SIMPATI5', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:08', ''),
          ('AX10', 'Axis 10.000', 5, 1, 1, 'AXIS10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:09', ''),
          ('AX20', 'Axis 20.000', 5, 1, 1, 'AXIS20', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:10', ''),
          ('AX50', 'Axis 50.000', 5, 1, 1, 'AXIS50', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:10', ''),
          ('BR5', 'Broom 5.000', 2, 1, 1, 'INDOSAT5BROOM', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '0000-00-00 00:00:00', ''),
          ('E25', 'Esia 25.000', 7, 1, 1, 'ESIA25', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:11', ''),
          ('E50', 'Esia 50.000', 7, 1, 1, 'ESIA50', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:11', ''),
          ('F10', 'Flexi 10.000', 8, 1, 1, 'FLEXI10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:12', ''),
          ('F20', 'Flexi 20.000', 8, 1, 1, 'FLEXI20', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:16', ''),
          ('F5', 'Flexi 5.000', 8, 1, 1, 'FLEXI5', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:17', ''),
          ('FR10', 'Fren 10.000', 6, 1, 1, 'FREN10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:17', ''),
          ('FR20', 'Fren 20.000', 6, 1, 1, 'FREN20', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:18', ''),
          ('FR25', 'Fren 25.000', 6, 1, 1, 'FREN25', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:19', ''),
          ('H10', 'Hepi 10.000', 10, 1, 1, 'HEPI10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:19', ''),
          ('H25', 'Hepi 25.000', 10, 1, 1, 'HEPI25', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:20', ''),
          ('H5', 'Hepi 5.000', 10, 1, 1, 'HEPI5', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:20', ''),
          ('M10', 'Mentari 10.000', 2, 1, 1, 'MENTARI10', 'IM10', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:21', ''),
          ('M5', 'Mentari 5.000', 2, 1, 1, 'MENTARI5', 'IM5', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:22', ''),
          ('S10', 'Simpati 10.000', 1, 1, 1, 'SIMPATI10', 'AS10', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:22', ''),
          ('S5', 'Simpati 5.000', 1, 1, 1, 'SIMPATI5', 'AS5', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:23', ''),
          ('SM10', 'Smart 10.000', 11, 1, 1, 'SMART10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:24', ''),
          ('SM20', 'Smart 20.000', 11, 1, 1, 'SMART20', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:24', ''),
          ('SM5', 'Smart 5.000', 11, 1, 1, 'SMART5', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:25', ''),
          ('SO10', 'StarOne 10.000', 9, 1, 1, 'SO10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:26', ''),
          ('SO20', 'StarOne 20.000', 9, 1, 1, 'SO20', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:26', ''),
          ('SO5', 'StarOne 5.000', 9, 1, 1, 'SO5', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:27', ''),
          ('SP10', 'Simpati 10.000 Promo', 1, 1, 1, 'SIMPATI10', 'AS10', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:27', ''),
          ('SP5', 'Simpati 5.000 Promo', 1, 1, 1, 'SIMPATI5', 'AS5', '', '', '', 'CH', 1, 'H2', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:28', ''),
          ('T10', 'Three 10.000', 4, 1, 1, 'THREE10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:29', ''),
          ('T20', 'Three 20.000', 4, 1, 1, 'THREE20', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:29', ''),
          ('T5', 'Three 5.000', 4, 1, 1, 'THREE5', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:30', ''),
          ('X10', 'XL 10.000', 3, 1, 1, 'XL10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:31', ''),
          ('X25', 'XL 25.000', 3, 1, 1, 'XL25', '', '', '', '', '', 0, '', 0, '', 0, '', 0, '', 0, '0000-00-00 00:00:00', ''),
          ('X5', 'XL 5.000', 3, 1, 1, 'XL5', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:31', '')''')
        cursor.close()
        self.dbconn.commit()
        self._createProcess(_prAuthorizer)
        self.ids = []
        self.c_message = DBCache(const.MESSAGE_PREFIX, config.DEFAULT_EXPIRE,
          const.MESSAGE_SQL)
        self.c_message.setConn(self.dbconn, self.cacheconn)
        self.idgen = range(50)
        self.deposit = DepositMutation(1, self.dbconn, self.cacheconn)
        self.deposit.credit('00001', 25000, 'setup credit', True)
#----------------------
    def runTest(self):
        test_function = [x for x in dir(self) if x[:6] == 'srtest']
        map(lambda x: getattr(self, x)(), sorted(test_function))
#----------------------
    def srtest10_authorized(self):  # TR_AUTHORIZED
        self.newRequest(('1', '00001', 'sms://08161940700', 'A10', '08128191891', 1, 0, 1))
        t = self._waitForRow('SELECT `status` from `transaction` WHERE '
          '`transaction_id`="1" and `status`={0}'.format(const.TR_AUTHORIZED))
        self.assertEqual(t, {'status': const.TR_AUTHORIZED})
        t = self._waitForRow('SELECT `mutation`,`type`,`deposit_balance` FROM '
          '`deposit_mutation` where `deposit_balance`=14850 and `agent_id`="00001"')
        self.assertEqual(t, {'mutation': 10150, 'type': "D", 'deposit_balance': 14850})
#----------------------
    def srtest20_wrong_number(self):  # TR_DENIED_WRONG_NUMBER
        self.newRequest(('2', '00001', 'sms://08161940700', 'A10', '08168191891', 1, 0, 1))
        t = self._waitForRow('SELECT `status` from `transaction` WHERE '
          '`transaction_id`="2" and `status`={0}'.format(const.TR_DENIED_WRONG_NUMBER))
        self.assertEqual(t, {'status': const.TR_DENIED_WRONG_NUMBER})
        t = self._waitForRow('SELECT `command` from `notify_out` where `parameters` '
          'LIKE "sms://08161940700,% 08168191891 %"')
        self.assertEqual(t, {'command': 'SMSG'})
#----------------------
    def srtest30_denied_product(self):  # TR_DENIED_PRODUCT
        self.newRequest(('3', '00001', 'sms://08161940700', 'XXX10', '08168191891', 1, 0, 2))
        self.newRequest(('4', '00001', 'sms://08161940700', 'AP5', '08168191891', 1, 0, 1))
        t = self._waitForRow('SELECT `status` from `transaction` WHERE '
          '`transaction_id`="3" and `status`={0}'.format(const.TR_DENIED_PRODUCT))
        self.assertEqual(t, {'status': const.TR_DENIED_PRODUCT})
        t = self._waitForRow('SELECT `command` from `notify_out` where `parameters` '
          'LIKE "sms://08161940700,% XXX10 %"')
        self.assertEqual(t, {'command': 'SMSG'})
        t = self._waitForRow('SELECT `status` from `transaction` WHERE '
          '`transaction_id`="4" and `status`={0}'.format(const.TR_DENIED_PRODUCT))
        self.assertEqual(t, {'status': const.TR_DENIED_PRODUCT})
        t = self._waitForRow('SELECT `command` from `notify_out` where `parameters` '
          'LIKE "sms://08161940700,% AP5 %"')
        self.assertEqual(t, {'command': 'SMSG'})
        t = self._waitForRow('SELECT COUNT(*) FROM `deposit_mutation`')
        self.assertEqual(t, {'COUNT(*)': 3})
#----------------------
    def srtest40_denied_balance(self):  # TR_DENIED_BALANCE
        self.newRequest(('5', '00001', 'sms://08161940700', 'AX50', '0838000111', 1, 0, 5))
        t = self._waitForRow('SELECT `status` from `transaction` WHERE '
          '`transaction_id`="5" and `status`={0}'.format(const.TR_DENIED_BALANCE))
        self.assertEqual(t, {'status': const.TR_DENIED_BALANCE})
        t = self._waitForRow('SELECT `command` from `notify_out` where `parameters` '
          'LIKE "sms://08161940700,% AX50 %"')
        self.assertEqual(t, {'command': 'SMSG'})
#----------------------
    def newRequest(self, p):
        cursor = self.dbconn.cursor()
        cursor.execute('INSERT INTO `transaction` (`transaction_id`,`agent_id`,'
          '`reg_protocol`,`product_id`,`msisdn_destination`,`order`,`status`,`operator_id`) '
          'VALUES (%s,%s,%s,%s,%s,%s,%s,%s)', p)
        cursor.close()
        self.dbconn.commit()
#----------------------
    def getMessage(self, msg, tosub={}):
        tmp = self.c_message.sGet(msg)['parse']
        tosub = dict(zip(map(lambda x: '<{0}>'.format(x),tosub.keys()),
          map(str,tosub.values())))
        if tosub == {}:
            return tmp
        return multipleReplace(tosub, tmp)