示例#1
0
文件: admin.py 项目: sridwan/meong
 def bundle(self, name, agent_id, price, pin):
     bc = AgentNotifier()
     c_agent = DBCache(const.AGENT_PREFIX, config.DEFAULT_EXPIRE,
                       const.AGENT_SQL)
     c_agent.setConn(bc.dbconn, bc.cacheconn)
     dm = DepositMutation(20, bc.dbconn, bc.cacheconn)
     ag = c_agent.sGet(agent_id)
     if not ag:
         return json.dumps({'success': 0, 'reason': 'AGENT NOT FOUND'})
     sql = '''SELECT * FROM `bundle` WHERE `bundle_name`=%s'''
     c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor)
     c.execute(sql, (name,))
     cs = c.fetchall()
     if len(cs) == 0:
         return json.dumps({'success': 0, 'reason': 'BUNDLE NOT FOUND'})            
     balance = dm.debit(agent_id, int(price), 'Bundle {0}'.format(name))
     if balance < 0:
         return json.dumps({'success': 0, 'reason': 'NOT ENOUGH DEPOSIT'})
     um = UnitMutation(5, bc.dbconn, bc.cacheconn)
     for r in c:
         um.credit(agent_id, r['product_id'], r['unit'], 0, name)
     msg = 'Add bundle {0} to {1}-{2} Rp {3}'.\
           format(name, agent_id, ag['agent_name'], thousandSeparator(price))
     for prot in ('ym://b_martian','ym://inileonard', 'ym://sridwan981'):
         bc.writeNotifyOut(prot, 'general_message', {'message': msg})
     bc.dbconn.commit()
     return json.dumps({'success': 1, 'reason': ''})            
示例#2
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)
示例#3
0
文件: admin.py 项目: sridwan/meong
 def transaction_success(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`,`base_price`,`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_RETRIED or \
                 int(r['status']) == const.TR_EXECUTED or \
                 int(r['status']) > const.TR_FAILED_GENERAL_REV:
         return json.dumps({'success': 0, 'reason': 'CANNOT SET STATUS'})
     if int(r['status']) >= const.TR_FAILED_HLR_REV and \
                 int(r['status']) <= const.TR_FAILED_GENERAL_REV :
         dm = DepositMutation(20, bc.dbconn, bc.cacheconn)
         dm.debit(r['agent_id'], r['sell_price'], 'Manual success {0}'.\
                   format(tran_id))
     c_agent_price = DBCache(const.AGENTPRICE_PREFIX, config.DEFAULT_EXPIRE, const.AGENTPRICE_SQL)
     owner = '{0:0>{1}}'.format(1, config.AGENT_ID_LENGTH)
     try:
         if r['agent_id'] != owner:
             fl = getFrontline(bc.dbconn, bc.cacheconn, r['agent_id'])
             if not fl:
                 self.logger.error('<countProfit> Frontline for agent {0} not found'.format(r['agent_id']))
                 raise
         else:
             fl = r['agent_id']
         ag = c_agent_price.sGet((fl, r['product_id'],))
         if not ag:
             self.logger.error('<countProfit> Price for agent {0} not found'.format(r['agent_id']))
             raise       
         profit = int(ag['sell_price']) - int(r['base_price'])
     except:
         profit = 0
     c.execute('''UPDATE `transaction` SET `status`=%s,`profit`=%s
                  WHERE `transaction_id`=%s''',
                  (const.TR_EXECUTED, profit, tran_id,))
     r['references'] = '0'
     bc.notifyTopupSucess(r)
     bc.dbconn.commit()
     return json.dumps({'success': 1, 'reason': 'SUCCESS'})
示例#4
0
class LoadBalance(AgentNotifier):
    """Process topup requests and balance them on available devices"""

    def __init__(self):
        super(LoadBalance, self).__init__("LB")
        self.operator = self._loadOperator()
        self.c_product = DBCache(const.PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.PRODUCT_SQL)
        self.c_op_product = DBCache(const.OP_PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.OP_PRODUCT_SQL)
        self.c_device = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL)
        self.c_base_price = DBCache(const.CHIP_BASE_PRICE_PREFIX, config.DEFAULT_EXPIRE, const.CHIP_BASE_PRICE_SQL)
        map(
            lambda x: x.setConn(self.dbconn, self.cacheconn),
            [self.c_product, self.c_op_product, self.c_device, self.c_base_price],
        )
        # self.hlr_cache = HLRCacheForLB(self.dbconn, self.cacheconn)
        # self.hlr_cache.cacheAllTopupDevice()
        self.lb = LBTopup(self.dbconn)
        self.lb.cleanRebuild()
        self.hm = HLRMap(self.dbconn, self.cacheconn)
        self.hm.rebuild()
        self.dm = DepositMutation(5, self.dbconn, self.cacheconn)
        self.last_op_prod = None
        self.last_device = None
        self.last_hlr_id = None
        self.last_tr_id = None
        self.last_tr_data = None
        self.change_method = None
        self.log = mylogger("LoadBalance", "loadbalance.log")

    def skipError(self):
        c = self.dbconn.cursor(MySQLdb.cursors.DictCursor)
        c.execute(
            """UPDATE `transaction` SET `status`=%s
                     WHERE `transaction_id`=%s""",
            (const.TR_FAILED_GENERAL, self.last_tr_id),
        )
        c.close()
        self.writeNotifyOut(
            "sms://08161940700",
            "general_message",
            {"message": "<LoadBalance>: Error while processing " "transaction {0}".format(self.last_tr_id)},
        )
        tr = self.last_tr_data
        tr["deposit"] = int(tr["deposit"]) + int(tr["sell_price"])
        self.notifyTopupFail(tr)
        self.dbconn.commit()
        print "Error while processing transaction {0}".format(self.last_tr_id)
        self.log.error("Error while processing transaction {0}".format(self.last_tr_id))

    def loadBalance(self):
        sql = """SELECT SQL_NO_CACHE `transaction_id`,`reg_protocol`,`agent_id`,
                 `product_id`,`operator_id`,`msisdn_destination`,`sell_price`,
                 `order`,`deposit` FROM `transaction`
                 WHERE `status`={0} and `method`='CH' LIMIT 100"""
        cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute(sql.format(const.TR_AUTHORIZED))
        rows = cursor.fetchall()
        if len(rows) == 0:
            cursor.close()
            return False
        for tran in rows:
            tr_id = tran["transaction_id"]
            self.last_tr_id = tr_id
            self.last_tr_data = dict(tran)
            dest_num = tran["msisdn_destination"]
            print "Topup id {2}, product {0} untuk nomor {1}".format(
                tran["product_id"], tran["msisdn_destination"], tran["transaction_id"]
            )
            self.log.info(
                "<loadBalance>Topup id {2}, product {0} untuk nomor {1}".format(
                    tran["product_id"], tran["msisdn_destination"], tran["transaction_id"]
                )
            )
            prod = self.c_product.sGet(tran["product_id"])
            if not prod:
                self.log.error(
                    '<loadBalance>Not found row in table "Product" ' "with product_id={0}".format(tran["product_id"])
                )
                continue
            op_id = prod["operator_id"]
            op_type = self.operator[op_id]["type"]
            opprod_list = self._extractOperatorProduct(prod)
            if op_type == "G":  # GSM
                result = self._executeTopupGSM(tr_id, op_id, opprod_list, dest_num)
                self.log.info(
                    "<loadBalance>Operator Product {1}\nTopup GSM {0}\nResult={2}".format(prod, opprod_list, result)
                )
            elif op_type == "C":  # CDMA
                result = self._executeTopupCDMA(tr_id, op_id, opprod_list, dest_num)
                self.log.info(
                    "<loadBalance>Operator Product {1}\nTopup CDMA {0}\nResult={2}".format(prod, opprod_list, result)
                )
            protocol = tran["reg_protocol"]
            if result == ET_SUCCESS:
                self._transactionInProgress(tr_id)
                if protocol[:3].lower() == "sms":
                    continue
                self.writeNotifyOut(
                    protocol, "transaction_in_progress", {"product_id": tran["product_id"], "dest": dest_num}
                )
                continue
            elif result == ET_CHANGE_METHOD:
                self._moveToNextMethod(tr_id, self.change_method)
                continue
            next_method = self._getNextMethod(prod)
            if next_method:
                self._moveToNextMethod(tr_id, next_method)
            elif result == ET_HLR_NOT_SUPPORTED:
                self._transactionResult(tr_id, const.TR_FAILED_HLR)
                self.writeNotifyOut(protocol, "hlr_not_supported", {"dest": dest_num})
            elif result == ET_OUT_OF_STOCK:
                self._transactionResult(tr_id, const.TR_OUT_OF_STOCK)
                agent_bal = int(tran["sell_price"]) + self.dm.getBalance(tran["agent_id"])
                self.writeNotifyOut(
                    protocol,
                    "out_of_stock",
                    {"product_id": tran["product_id"], "balance": thousandSeparator(agent_bal)},
                )
        cursor.close()
        self.dbconn.commit()
        return True

    def _moveToNextMethod(self, tr_id, method):
        cursor = self.dbconn.cursor()
        sql = """UPDATE `transaction` set `method`=%s, `hlr_id`=%s WHERE
            `transaction_id`=%s"""
        cursor.execute(sql, (method, self.last_hlr_id, tr_id))
        cursor.close()

    def _getNextMethod(self, prod):
        a = ("method_1_active", "method_2_active", "method_3_active", "method_4_active", "method_5_active")
        m = ("method_1", "method_2", "method_3", "method_4", "method_5")
        methods = map(lambda x: prod[x], [_m for _a, _m in zip(a, m) if prod[_a] == 1])
        try:
            i = methods.index("CH")
            if i >= (len(methods) - 1):
                return None
            return methods[i + 1]
        except:
            return None

    def _extractOperatorProduct(self, prod):
        result = []
        tmp = (
            "operator_product_id_1",
            "operator_product_id_2",
            "operator_product_id_3",
            "operator_product_id_4",
            "operator_product_id_5",
        )
        for i in tmp:
            if len(prod[i]) > 0:
                result.append(prod[i])
        return result

    def _transactionResult(self, tr_id, status):
        cursor = self.dbconn.cursor()
        sql = """UPDATE `transaction` set `status`=%s where `transaction_id`=%s"""
        cursor.execute(sql, (status, tr_id))
        cursor.close()

    def _transactionInProgress(self, tr_id):
        supplier_id = self.c_device.sGet(self.last_device)["supplier_id"]
        base_price = self.c_base_price.sGet((supplier_id, self.last_op_prod))["base_price"]
        cursor = self.dbconn.cursor()
        sql = """UPDATE `transaction` set `status`=%s, `operator_product_id`=%s,
            `device_id`=%s, `hlr_id`=%s, `supplier_id`=%s, `base_price`=%s where `transaction_id`=%s"""
        cursor.execute(
            sql,
            (
                const.TR_INPROGRESS,
                self.last_op_prod,
                self.last_device,
                self.last_hlr_id,
                supplier_id,
                base_price,
                tr_id,
            ),
        )
        cursor.close()

    def _executeTopupGSM(self, tr_id, op_id, prod_list, dest):
        hlr = dest[:8]
        result = self._executeTopup(tr_id, op_id, prod_list, dest, hlr)
        return result

    def _executeTopupCDMA(self, tr_id, op_id, prod_list, dest):
        hlr2 = dest[:4]
        return self._executeTopup(tr_id, op_id, prod_list, dest, hlr2)

    def _executeTopup(self, tr_id, op_id, prod_list, dest, hlr):
        """"""

        def stockOK(dev_id, prod_list):
            for prod_id in prod_list:
                op_prod = self.c_op_product.sGet(prod_id)
                if not self._checkUnitOrBalance(dev_id, op_prod):
                    continue
                else:
                    return op_prod
            return None

        hlr_id, method = self.hm.getHLRID2(op_id, hlr)
        if not hlr_id:
            hlr_id = 0
        elif method.upper() != "CH":
            self.change_method = method
            return ET_CHANGE_METHOD
        dev_list = self.lb.getLB(op_id, hlr_id)
        picked_dev_id = None
        for dev in dev_list:
            dev_id = dev["device_id"]
            op_prod = stockOK(dev_id, prod_list)
            if not op_prod:
                continue
            else:
                picked_dev_id = dev_id
                break
        if not picked_dev_id:
            return ET_OUT_OF_STOCK
        topup_parse = op_prod["topup_parse"]
        self._sendToLeaf(tr_id, dev_id, topup_parse, dest)
        self.last_op_prod = op_prod["operator_product_id"]
        self.last_device = picked_dev_id
        self.last_hlr_id = hlr_id
        self.lb.use(picked_dev_id)
        # print('ET_SUCCESS dev: {0}'.format(picked_dev_id))
        return ET_SUCCESS

    def _checkUnitOrBalance(self, dev_id, op_prod):
        """Check unit or balance of a chip"""

        def checkUnit(dev_id, prod_id):
            cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor)
            cursor.execute(
                "SELECT SQL_NO_CACHE `balance_unit` from `unit` WHERE "
                "`device_id`=%s and `operator_product_id`=%s LIMIT 1",
                (dev_id, prod_id),
            )
            r = cursor.fetchone()
            # print('<_checkUnitOrBalance - checkUnit> dev_id={1}, prod_id={2}, result={0}'.format(r, dev_id, prod_id))
            cursor.close()
            if not r:
                return False
            if int(r["balance_unit"]) < 1:
                return False
            return True

        def checkBalance(dev_id, amount):
            cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor)
            cursor.execute(
                "SELECT SQL_NO_CACHE `topup_balance` from `balance` " "WHERE `device_id`=%s LIMIT 1", (dev_id,)
            )
            r = cursor.fetchone()
            cursor.close()
            if not r:
                return False
            if int(r["topup_balance"]) < amount:
                return False
            return True

        if not op_prod:
            return False
        bal_type = op_prod["balance_flag"]
        unit_used = op_prod["unit_used"]
        # print('<_checkUnitOrBalance> bal_type={0}, unit_used={1}'.format(bal_type, unit_used))
        if bal_type.upper() == "U":
            if checkUnit(dev_id, unit_used):
                return True
        else:
            if checkBalance(dev_id, int(op_prod["topup_amount_chip"])):
                return True
        return False

    def _sendToLeaf(self, tran_id, dev_id, parse, dest):
        pin = self.c_device.sGet(dev_id)["pin"]
        server_id, port = dev_id.split(".")
        leaf_server = "{0}@{2}/{1}".format(config.LEAFSERVER, server_id, config.MSG_SERVER)
        parse = multipleReplace({"<dest>": dest, "<pin>": pin}, parse)
        # msg = '{0},{1},{2},{3},{4}'.format(port, tran_id, parse, dest, pin)
        msg = "{0}.{1},{2},{3}".format(server_id, port, tran_id, parse)
        self.sendMessage(leaf_server, "JBDV", msg, commit=False)

    def _loadOperator(self):
        """Get self.operator"""
        result = {}
        cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute(
            """SELECT `operator_id`,`operator_name`,`type`,`prefix`
        FROM `operator` order by `operator_id` ASC"""
        )
        for op in cursor:
            op["prefix"] = op["prefix"].split(",")
            result[op["operator_id"]] = op
        cursor.close()
        return result
示例#5
0
class TestDeviceAdmin(TestAdminHelper):
    def setUp(self):
        self.bc = BaseComponent()
        self.dbconn = self.bc.dbconn
        self.cacheconn = self.bc.cacheconn
        cursor = self.dbconn.cursor()
        cursor.execute('DELETE FROM `hlr_cache`')
        cursor.execute('DELETE FROM `hlr`')
        cursor.executemany('INSERT INTO `hlr` VALUES (%s,%s,%s,%s,%s,%s)', [
          ('1', '2', 'DKI Jakarta', '100,101,102,103', '2010-10-22 15:29:52', 'bernard'),
          ('2', '1', 'Meong1', '110,111,112', '0000-00-00 00:00:00', 'test'),
          ('3', '1', 'Meong2', '210,211,212', '0000-00-00 00:00:00', 'test'),
          ('4', '3', 'Guk1', '330,331,332', '0000-00-00 00:00:00', 'test'),
        ])
        cursor.execute('DELETE FROM `devices`')
        cursor.executemany('INSERT INTO `devices` VALUES (%s, %s, %s, %s, %s, %s,\
          %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', [
        ('SERVER1.COM10', 'SERVER1', 'COM10', '1', '201001240601026', 'WAVECOM', 'GSM', '1', '0', '', 'MKIOS1', '0', '0', '', '1', '0000-00-00', '2010-11-19 17:40:39', ''),
        ('SERVER1.COM11', 'SERVER1', 'COM11', '1', '201001240600838', 'WAVECOM', 'GSM', '2', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-19 17:22:31', ''),
        ('SERVER1.COM20', 'SERVER1', 'COM20', '1', '201001240600135', 'WAVECOM', 'GSM', '3', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-19 17:28:38', ''),
        ('SERVER1.COM21', 'SERVER1', 'COM21', '1', '201001240600994', 'WAVECOM', 'GSM', '1', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-19 17:28:58', ''),
        ('SERVER1.COM22', 'SERVER1', 'COM22', '1', '201001240601067', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM23', 'SERVER1', 'COM23', '1', '201001240601042', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM24', 'SERVER1', 'COM24', '1', '201001240600671', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM25', 'SERVER1', 'COM25', '1', '351011513521015', 'SIEMENS', 'C55', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM26', 'SERVER1', 'COM26', '1', '010348005275525', 'SIEMENS', 'C55', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM27', 'SERVER1', 'COM27', '1', '03316190103', 'NOKIA', '6235i', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM5', 'SERVER1', 'COM5', '1', '201001240600259', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM6', 'SERVER1', 'COM6', '1', '201001240600762', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM7', 'SERVER1', 'COM7', '1', '201001240600564', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM8', 'SERVER1', 'COM8', '1', '201001240600515', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ('SERVER1.COM9', 'SERVER1', 'COM9', '1', '201001240600655', 'WAVECOM', 'GSM', '0', '0', '', '', '0', '0', '', '1', '0000-00-00', '2010-11-09 21:12:47', ''),
        ])
        self.dbconn.commit()
        self.cacheconn.delete(HLR_CACHEKEY)
        self.h2 = HLRCacheForLB(self.dbconn, self.cacheconn)
        cursor.close()
        self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE,
            const.DEVICES_SQL)
        self.c_dev.setConn(self.dbconn, self.cacheconn)
        self.c_dev.sGet('SERVER1.COM10')
        self.c_dev.sGet('SERVER1.COM11')
        self.c_dev.sGet('SERVER1.COM20')
        self.c_dev.sGet('SERVER1.COM21')
        self.c_dev.sGet('SERVER1.COM22')
        self.c_dev.sGet('SERVER1.COM23')
        self.c_dev.sGet('SERVER1.COM24')
        self.c_dev.sGet('SERVER1.COM25')
        self.c_dev.sGet('SERVER1.COM26')
        self.c_dev.sGet('SERVER1.COM27')
        self.c_dev.sGet('SERVER1.COM5')
        self.c_dev.sGet('SERVER1.COM6')
        self.c_dev.sGet('SERVER1.COM7')
        self.c_dev.sGet('SERVER1.COM8')
        self.c_dev.sGet('SERVER1.COM9')
#----------------------
    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_adminHelper(self):
        post_data = {
          'device_id': 'SERVER1.COM10,SERVER1.COM11,SERVER1.COM20,SERVER1.COM21'
        }
        self._callAdminHelper('device_preupdate', post_data)
        cursor = self.dbconn.cursor()
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s where `device_id`=%s',
          (const.DR_TOPUP, 1, 'SERVER1.COM10'))
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s where `device_id`=%s',
          (const.DR_TOPUP, 1, 'SERVER1.COM11'))
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s, `active`=0 WHERE \
          `device_id`=%s',
          (const.DR_TOPUP, 1, 'SERVER1.COM20'))
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s where `device_id`=%s',
          (const.DR_TOPUP, 1, 'SERVER1.COM21'))
        cursor.close()
        self.dbconn.commit()
        self._callAdminHelper('device_postupdate', post_data)
        tmp = self.h2._getHLRCache()
        self.assertEqual(
          ['SERVER1.COM10', 'SERVER1.COM11', 'SERVER1.COM21'],
          sorted(tmp[HLR_DEVICE][1]))
        x = self.c_dev.sGet('SERVER1.COM10')
        self.assertEqual(int(x['function']), const.DR_TOPUP)
        x = self.c_dev.sGet('SERVER1.COM11')
        self.assertEqual(int(x['function']), const.DR_TOPUP)
        x = self.c_dev.sGet('SERVER1.COM21')
        self.assertEqual(int(x['function']), const.DR_TOPUP)
#----------------------
    def srtest20_adminHelper(self):
        post_data = {
          'device_id': 'SERVER1.COM5,SERVER1.COM6,SERVER1.COM7'
        }
        self._callAdminHelper('device_preupdate', post_data)
        cursor = self.dbconn.cursor()
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s where `device_id`=%s',
          (const.DR_TOPUP, 2, 'SERVER1.COM5'))
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s where `device_id`=%s',
          (const.DR_TOPUP, 2, 'SERVER1.COM6'))
        cursor.execute('UPDATE `devices` set `function`=%s, `hlr_id`=%s where `device_id`=%s',
          (const.DR_TOPUP, 2, 'SERVER1.COM7'))
        cursor.close()
        self.dbconn.commit()
        self._callAdminHelper('device_postupdate', post_data)
        tmp = self.h2._getHLRCache()
        self.assertEqual(
          ['SERVER1.COM5', 'SERVER1.COM6', 'SERVER1.COM7'],
          sorted(tmp[HLR_DEVICE][2]))
#----------------------
    def srtest30_adminHelper(self):
        post_data = {
          'device_id': 'SERVER1.COM20'
        }
        self._callAdminHelper('device_preupdate', post_data)
        cursor = self.dbconn.cursor()
        cursor.execute('UPDATE `devices` set `active`=1, `hlr_id`=%s where `device_id`=%s',
          (3, 'SERVER1.COM20'))
        cursor.close()
        self.dbconn.commit()
        self._callAdminHelper('device_postupdate', post_data)
        tmp = self.h2._getHLRCache()
        self.assertEqual(
          ['SERVER1.COM10', 'SERVER1.COM11', 'SERVER1.COM21'],
          sorted(tmp[HLR_DEVICE][1]))
        self.assertEqual(
          ['SERVER1.COM20',],
          sorted(tmp[HLR_DEVICE][3]))
示例#6
0
文件: TestCore.py 项目: sridwan/meong
class TestCore(TestCoreComponent):
    def setUp(self):
        super(TestCore, self).setUp()
        self.cacheconn.flush_all()
        self._initXMPP(config.LEAFSERVER, config.LEAFSERVER_PASS, 'SERVER1')
        self._initXMPP2('imtest', 'test', 'SERVER1')
        self.setUpTable()
        # TODO: _prConfigHandler
        createProcess(notifyOut, prNotifyIn, prIMDispatch,
            prTopupParser, prAuthorizer, prLoadBalance, prHighPrioritySync,
            prLowPrioritySync)
        HLRCacheForLB(self.dbconn, self.cacheconn).cacheAllTopupDevice()
        time.sleep(8)
        self.c_message = DBCache(const.MESSAGE_PREFIX, config.DEFAULT_EXPIRE,
          const.MESSAGE_SQL)
        self.c_message.setConn(self.dbconn, self.cacheconn)
        showPID()
#----------------------
    def tearDown(self):
        shutdown()
        super(TestCore, self).tearDown()
#----------------------
    def _newSMS(self, cmd, p):
        p = p.format(datetime.now().strftime('%y/%m/%d %H:%M:%S'))
        nin = '{0}@{1}'.format(config.NOTIFYIN, config.MSG_SERVER)
        self._sendCommand(nin, cmd, p)
#----------------------
    def _newIM(self, cmd, p):
        p = p.format(datetime.now().strftime('%y/%m/%d %H:%M:%S'))
        elt = 'elogictopup@yahoo.{0}'.format(config.MSG_SERVER)
        self._sendCommand2(elt, cmd, p)
#----------------------
    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)
#----------------------
    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_topup_parser(self):
        # unknown sender
        self._newSMS('FRDV', 'COM51,sms://919191,{0},testing')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, self._getMessage('agent_invalid'))
        # timeout
        self._newSMS('FRDV', 'COM50,sms://08161940700,09/12/15 00:00:00,A10.0812111222.9999')
        r = self._waitForRow('SELECT `command` from `notify_in` where `status`=2 ' \
            'AND `parameters`="COM50,sms://08161940700,09/12/15 00:00:00,A10.0812111222.9999"')
        self.assertEqual(r['command'].upper(), 'UNKN')
        # wrong pin
        self._newSMS('FRDV', 'COM51,sms://08161940700,{0},A10.0812111222.4321')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, self._getMessage('agent_invalid'))
        # wrong product
        self._newSMS('FRDV', 'COM51,sms://08161940700,{0},XXX10.0812111222.9999')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, self._getMessage('prod_not_registered', {'product_id': 'XXX10'}))
        # wrong format
        self._newSMS('FRDV', 'COM50,sms://08161940700,{0},A10.A.0812111222.9999')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, self._getMessage('wrong_req_format'))
        # success, single order
        self._newSMS('FRDV', 'COM50,sms://08161940700,{0},A10.0812111222.9999')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, 'ussd://*677*0812111222*10*122#')
        # get order status
        self._newSMS('FRDV', 'COM51,sms://08161940700,{0},A10.0812111222.9999')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, 'Topup produk A10 untuk 0812111222 DALAM PROSES')
        # multiple order
        self._newSMS('FRDV', 'COM51,sms://08161940700,{0},AX20.0812999888.S10.08128191891.F20.' \
            '02123881891.9999')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, 'Tujuan 0812999888 bukan jaringan Axis.')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, 'Nomor tujuan 08128191891 di luar area kami.')
        m = self._waitForMessage(10)
        _1, _2, m = m.rpartition(',')
        self.assertEqual(m, 'Nomor tujuan 02123881891 di luar area kami.')
#----------------------
    def srtest20_(self):
        pass
#----------------------
    def setUpTable(self):
        self._resetTable('Transaction')
        self._resetTable('Notify_In')
        self._resetTable('Notify_Out')
        self._resetTable('Deposit_Mutation')
        self._resetTable('Deposit_Transfer')
        self._resetTable('Message')
        self._resetTable('Nin_Unknown')
        cursor = self.dbconn.cursor()
        cursor.execute('DELETE FROM `hlr_cache`')
        cursor.execute('DELETE FROM `devices`')
        cursor.execute('''INSERT INTO `devices` (`device_id`, `server_id`, `port`, `active`, `imei`, `brand`, `type`, `operator_id`, `hlr_id`, `msidn_device`, `device_name`, `supplier_id`, `function`, `pin`, `status`, `expired_date`, `last_update`, `last_update_by`) VALUES
            ('SERVER1.COM10', 'SERVER1', 'COM10', 1, '201001240601026', 'WAVECOM', 'GSM', 2, 1, '', 'MKIOS1', 0, 3, '110', 0, '0000-00-00', '2010-11-19 17:40:39', ''),
            ('SERVER1.COM11', 'SERVER1', 'COM11', 1, '201001240600838', 'WAVECOM', 'GSM', 2, 1, '', '', 0, 3, '111', 0, '0000-00-00', '2011-01-12 16:42:41', ''),
            ('SERVER1.COM20', 'SERVER1', 'COM20', 1, '201001240600135', 'WAVECOM', 'GSM', 2, 1, '', '', 0, 3, '120', 0, '0000-00-00', '2011-01-12 16:42:47', ''),
            ('SERVER1.COM21', 'SERVER1', 'COM21', 1, '201001240600994', 'WAVECOM', 'GSM', 2, 1, '', '', 0, 3, '121', 0, '0000-00-00', '2011-01-12 16:43:05', ''),
            ('SERVER1.COM22', 'SERVER1', 'COM22', 1, '201001240601067', 'WAVECOM', 'GSM', 1, 2, '', '', 0, 3, '122', 0, '0000-00-00', '2011-01-12 16:43:05', ''),
            ('SERVER1.COM23', 'SERVER1', 'COM23', 1, '201001240601042', 'WAVECOM', 'GSM', 1, 2, '', '', 0, 3, '123', 0, '0000-00-00', '2011-01-12 16:43:05', ''),
            ('SERVER1.COM24', 'SERVER1', 'COM24', 1, '201001240600671', 'WAVECOM', 'GSM', 1, 2, '', '', 0, 3, '124', 0, '0000-00-00', '2011-01-12 16:43:05', ''),
            ('SERVER1.COM25', 'SERVER1', 'COM25', 1, '351011513521015', 'SIEMENS', 'C55', 1, 2, '', '', 0, 3, '125', 0, '0000-00-00', '2011-01-12 16:43:06', ''),
            ('SERVER1.COM26', 'SERVER1', 'COM26', 1, '010348005275525', 'SIEMENS', 'C55', 1, 3, '', '', 0, 3, '126', 0, '0000-00-00', '2011-01-12 16:43:06', ''),
            ('SERVER1.COM27', 'SERVER1', 'COM27', 1, '03316190103', 'NOKIA', '6235i', 1, 3, '', '', 0, 3, '127', 0, '0000-00-00', '2011-01-12 16:43:07', ''),
            ('SERVER1.COM30', 'SERVER1', 'COM30', 1, '201001240600655', 'WAVECOM', 'CDMA', 7, 7, '', '', 0, 3, '109', 0, '0000-00-00', '2010-11-09 21:12:47', ''),
            ('SERVER1.COM5', 'SERVER1', 'COM5', 1, '201001240600259', 'WAVECOM', 'GSM', 1, 3, '', '', 0, 3, '105', 0, '0000-00-00', '2010-11-09 21:12:47', ''),
            ('SERVER1.COM50', 'SERVER1', 'COM50', 1, '', '', '', 0, 0, '', '', 0, 1, '', 0, '0000-00-00', '0000-00-00 00:00:00', ''),
            ('SERVER1.COM51', 'SERVER1', 'COM51', 1, '', '', '', 0, 0, '', '', 0, 1, '', 0, '0000-00-00', '0000-00-00 00:00:00', ''),
            ('SERVER1.COM52', 'SERVER1', 'COM52', 1, '', '', '', 0, 0, '', '', 0, 2, '', 0, '0000-00-00', '0000-00-00 00:00:00', ''),
            ('SERVER1.COM53', 'SERVER1', 'COM53', 1, '', '', '', 0, 0, '', '', 0, 2, '', 0, '0000-00-00', '0000-00-00 00:00:00', ''),
            ('SERVER1.COM54', 'SERVER1', 'COM54', 1, '', '', '', 0, 0, '', '', 0, 2, '', 0, '0000-00-00', '0000-00-00 00:00:00', ''),
            ('SERVER1.COM6', 'SERVER1', 'COM6', 1, '201001240600762', 'WAVECOM', 'GSM', 1, 3, '', '', 0, 3, '106', 0, '0000-00-00', '2010-11-09 21:12:47', ''),
            ('SERVER1.COM7', 'SERVER1', 'COM7', 1, '201001240600564', 'WAVECOM', 'GSM', 3, 4, '', '', 0, 3, '107', 0, '0000-00-00', '2010-11-09 21:12:47', ''),
            ('SERVER1.COM8', 'SERVER1', 'COM8', 1, '201001240600515', 'WAVECOM', 'GSM', 3, 4, '', '', 0, 3, '108', 0, '0000-00-00', '2010-11-09 21:12:47', ''),
            ('SERVER1.COM9', 'SERVER1', 'COM9', 1, '201001240600515', 'WAVECOM', 'GSM', 3, 4, '', '', 0, 3, '109', 0, '0000-00-00', '2010-11-09 21:12:47', '')''')
        cursor.execute('DELETE FROM `hlr`')    
        cursor.execute('''INSERT INTO `hlr` (`hlr_id`, `operator_id`, `location`, `hlr`, `last_update`, `last_update_by`) VALUES
            (1, 2, 'DKI Jakarta', '100,101,102,103', '2010-10-22 15:29:52', 'bernard'),
            (2, 1, 'Meong1', '110,111,112', '0000-00-00 00:00:00', 'test'),
            (3, 1, 'Meong2', '210,211,212', '0000-00-00 00:00:00', 'test'),
            (7, 7, 'Meong2', '021', '0000-00-00 00:00:00', 'test'),
            (4, 3, 'Guk1', '330,331,332', '0000-00-00 00:00:00', 'test')''')    
        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 `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, 'INDOSAT10', '', '', '', '', 'CH', 1, '', 0, '', 0, '', 0, '', 0, '2010-07-08 18:48:21', ''),
          ('M5', 'Mentari 5.000', 2, 1, 1, 'INDOSAT5', '', '', '', '', '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.execute('DELETE FROM `balance`')
        cursor.execute('''INSERT INTO `balance` (`device_id`, `topup_balance`, `last_update`, `last_update_by`) VALUES
          ('SERVER1.COM7', 100000, '2010-10-25 16:05:56', ''),
          ('SERVER1.COM8', 100000, '2010-10-25 16:05:56', ''),
          ('SERVER1.COM9', 100000, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM30', 100000, '0000-00-00 00:00:00', '')''')
        cursor.execute('DELETE FROM `unit`')
        cursor.execute('''INSERT INTO `unit` (`device_id`, `operator_product_id`, `balance_unit`, `last_update`, `last_update_by`) VALUES
          ('SERVER1.COM10', 'INDOSAT5', 20, '2010-10-25 16:05:56', ''),
          ('SERVER1.COM10', 'INDOSAT10', 20, '2010-10-25 16:05:59', ''),
          ('SERVER1.COM11', 'INDOSAT5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM11', 'INDOSAT10', 10, '2010-10-27 15:52:40', ''),
          ('SERVER1.COM20', 'INDOSAT5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM20', 'INDOSAT10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM21', 'INDOSAT5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM21', 'INDOSAT10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM22', 'AS10', 20, '2010-10-25 16:05:56', ''),
          ('SERVER1.COM22', 'SIMPATI5', 20, '2010-10-25 16:05:59', ''),
          ('SERVER1.COM23', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM23', 'SIMPATI5', 10, '2010-10-27 15:52:40', ''),
          ('SERVER1.COM24', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM24', 'SIMPATI5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM25', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM25', 'SIMPATI5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM26', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM26', 'SIMPATI5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM27', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM27', 'SIMPATI5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM30', 'ESIA5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM30', 'ESIA10', 20, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM5', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM5', 'SIMPATI5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM6', 'AS10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM6', 'SIMPATI5', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM7', 'XL5', 0, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM7', 'XL10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM8', 'XL5', 0, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM8', 'XL10', 10, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM9', 'XL5', 0, '0000-00-00 00:00:00', ''),
          ('SERVER1.COM9', 'XL10', 10, '0000-00-00 00:00:00', '')''')
        cursor.execute('DELETE FROM `operator_product`')
        cursor.execute('''INSERT INTO `operator_product` (`operator_product_id`, `balance_flag`, `unit_used`, `operator_id`, `topup_amount_chip`, `topup_parse`, `last_update`, `last_update_by`) VALUES
            ('AS10', 'U', 'AS10', 1, 0, 'ussd://*677*<dest>*10*<pin>#', '2010-10-27 15:41:47', 'admin'),
            ('AS100', 'U', 'AS100', 1, 0, 'ussd://*677*<dest>*100*<pin>#', '2010-10-27 15:41:50', 'admin'),
            ('AS15', 'U', 'AS15', 1, 0, 'ussd://*677*<dest>*15*<pin>#', '2010-10-27 15:41:53', 'admin'),
            ('AS20', 'U', 'AS20', 1, 0, 'ussd://*677*<dest>*20*<pin>#', '2010-10-27 15:41:56', 'admin'),
            ('AS25', 'U', 'AS25', 1, 0, 'ussd://*677*<dest>*25*<pin>#', '2010-10-27 15:41:59', 'admin'),
            ('AS5', 'U', 'AS5', 1, 0, 'ussd://*677*<dest>*5*<pin>#', '2010-10-27 15:42:02', 'admin'),
            ('AS50', 'U', 'AS50', 1, 0, 'ussd://*677*<dest>*50*<pin>#', '2010-10-27 15:42:05', 'admin'),
            ('AXIS10', 'B', '', 5, 10000, 'data://12.<dest>..<pin>$', '2010-10-27 15:47:38', 'admin'),
            ('AXIS100', 'B', '', 5, 100000, 'data://14.<dest>..<pin>$', '2010-10-27 15:47:38', 'admin'),
            ('AXIS20', 'B', '', 5, 20000, 'data://15.20000..<dest>..<pin>$', '2010-10-27 15:47:36', 'admin'),
            ('AXIS25', 'B', '', 5, 25000, 'data://13.<dest>..<pin>$', '2010-10-27 15:47:35', 'admin'),
            ('AXIS5', 'B', '', 5, 5000, 'data://11.<dest>..<pin>$', '2010-10-27 15:47:35', 'admin'),
            ('AXIS50', 'B', '', 5, 50000, 'data://15.50000..<dest>..<pin>$', '2010-10-27 15:47:35', 'admin'),
            ('ESIA1', 'U', 'ESIA1', 7, 1000, 'sms://isi <dest> 1 <pin>,898', '2010-10-27 15:47:34', 'admin'),
            ('ESIA10', 'U', 'ESIA10', 7, 10000, 'sms://isi <dest> 10 <pin>,898', '2010-10-27 15:47:34', 'admin'),
            ('ESIA11', 'B', '', 7, 11000, 'sms://isi <dest> 11 <pin>,898', '2010-10-27 15:47:34', 'admin'),
            ('ESIA15', 'B', '', 7, 15000, 'sms://isi <dest> 15 <pin>,898', '2010-10-27 15:47:34', 'admin'),
            ('ESIA20', 'B', '', 7, 20000, 'sms://isi <dest> 20 <pin>,898', '2010-10-27 15:47:33', 'admin'),
            ('ESIA5', 'U', 'ESIA5', 7, 5000, 'sms://isi <dest> 5 <pin>,898', '2010-10-27 15:47:33', 'admin'),
            ('FLEXI10', 'B', '', 8, 10000, 'sms://TOP#<pin>#<dest>#F10,899', '2010-10-27 15:47:32', 'admin'),
            ('FLEXI100', 'B', '', 8, 100000, 'sms://TOP#<pin>#<dest>#100,899', '2010-10-27 15:47:32', 'admin'),
            ('FLEXI20', 'B', '', 8, 20000, 'sms://TOP#<pin>#<dest>#F20,899', '2010-10-27 15:47:31', 'admin'),
            ('FLEXI5', 'B', '', 8, 5000, 'sms://TOP#<pin>#<dest>#F5,899', '2010-10-27 15:47:30', 'admin'),
            ('FLEXI50', 'B', '', 8, 50000, 'sms://TOP#<pin>#<dest>#50,899', '0000-00-00 00:00:00', 'admin'),
            ('INDOSAT10', 'U', 'INDOSAT10', 2, 0, 'data://11.<dest>.11.<pin>$', '0000-00-00 00:00:00', 'admin'),
            ('INDOSAT100', 'U', 'INDOSAT100', 2, 0, 'data://11.<dest>.51.<pin>$', '2010-10-27 15:42:15', 'admin'),
            ('INDOSAT100BROOM', 'U', 'INDOSAT100', 2, 0, 'data://11.9<dest>.51.<pin>$', '2010-10-27 15:43:40', 'admin'),
            ('INDOSAT10BROOM', 'U', 'INDOSAT10', 2, 0, 'data://11.9<dest>.11.<pin>$', '2010-10-27 15:43:35', 'admin'),
            ('INDOSAT10GPRS', 'U', 'INDOSAT10', 2, 0, 'data://11.<dest>.13.<pin>$', '2010-10-27 15:43:32', 'admin'),
            ('INDOSAT10SMS', 'U', 'INDOSAT10', 2, 0, 'data://11.<dest>.12.<pin>$', '2010-10-27 15:43:29', 'admin'),
            ('INDOSAT25', 'U', 'INDOSAT25', 2, 0, 'data://11.<dest>.31.<pin>$', '2010-10-27 15:42:15', 'admin'),
            ('INDOSAT25BROOM', 'U', 'INDOSAT25', 2, 0, 'data://11.9<dest>.31.<pin>$', '2010-10-27 15:43:26', 'admin'),
            ('INDOSAT25GPRS', 'U', 'INDOSAT25', 2, 0, 'data://11.<dest>.33.<pin>$', '2010-10-27 15:43:21', 'admin'),
            ('INDOSAT25SMS', 'U', 'INDOSAT25', 2, 0, 'data://11.<dest>.32.<pin>$', '2010-10-27 15:43:17', 'admin'),
            ('INDOSAT5', 'U', 'INDOSAT5', 2, 0, 'data://11.<dest>.6.5000.1.<pin>$', '2010-10-27 15:42:15', 'admin'),
            ('INDOSAT50', 'U', 'INDOSAT50', 2, 0, 'data://11.<dest>.41.<pin>$', '2010-10-27 15:42:15', 'admin'),
            ('INDOSAT50BROOM', 'U', 'INDOSAT50', 2, 0, 'data://11.9<dest>.41.<pin>$', '2010-10-27 15:43:13', 'admin'),
            ('INDOSAT5BROOM', 'U', 'INDOSAT5', 2, 0, 'data://11.9<dest>.6.5000.1.<pin>$', '2010-10-27 15:42:42', 'admin'),
            ('INDOSAT5GPRS', 'U', 'INDOSAT5', 2, 0, 'data://11.<dest>.6.5000.3.<pin>$', '2010-10-27 15:42:37', 'admin'),
            ('INDOSAT5SMS', 'U', 'INDOSAT5', 2, 0, 'data://11.<dest>.6.5000.2.<pin>$', '2010-10-27 15:42:33', 'admin'),
            ('SIMPATI10', 'U', 'SIMPATI10', 1, 0, 'ussd://*777*<dest>*10*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('SIMPATI100', 'U', 'SIMPATI100', 1, 0, 'ussd://*777*<dest>*50*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('SIMPATI20', 'U', 'SIMPATI20', 1, 0, 'ussd://*777*<dest>*20*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('SIMPATI5', 'U', 'SIMPATI5', 1, 0, 'ussd://*777*<dest>*5*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('SIMPATI50', 'U', 'SIMPATI50', 1, 0, 'ussd://*777*<dest>*25*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('THREE1', 'B', '', 4, 1000, 'data://+11.<dest>..<dest>..1000..1000..<pin>$', '2010-10-27 15:48:32', 'admin'),
            ('THREE10', 'B', '', 4, 10000, 'data://+11.<dest>..<dest>..10000..10000..<pin>$', '2010-10-27 15:48:33', 'admin'),
            ('THREE100', 'B', '', 4, 100000, 'data://+11.<dest>..<dest>..100000..100000..<pin>$', '2010-10-27 15:48:33', 'admin'),
            ('THREE2', 'B', '', 4, 2000, 'data://+11.<dest>..<dest>..2000..2000..<pin>$', '2010-10-27 15:48:34', 'admin'),
            ('THREE20', 'B', '', 4, 20000, 'data://+11.<dest>..<dest>..20000..20000..<pin>$', '2010-10-27 15:48:37', 'admin'),
            ('THREE3', 'B', '', 4, 3000, 'data://+11.<dest>..<dest>..3000..3000..<pin>$', '2010-10-27 15:48:37', 'admin'),
            ('THREE30', 'B', '', 4, 30000, 'data://+11.<dest>..<dest>..30000..30000..<pin>$', '2010-10-27 15:48:37', 'admin'),
            ('THREE4', 'B', '', 4, 4000, 'data://+11.<dest>..<dest>..4000..4000..<pin>$', '2010-10-27 15:48:38', 'admin'),
            ('THREE5', 'B', '', 4, 5000, 'data://+11.<dest>..<dest>..5000..5000..<pin>$', '2010-10-27 15:48:39', 'admin'),
            ('THREE50', 'B', '', 4, 50000, 'data://+11.<dest>..<dest>..50000..50000..<pin>$', '2010-10-27 15:48:39', 'admin'),
            ('XL1', 'U', 'XL1', 3, 0, 'USSD://*101*1000*00*<dest>*<pin>#', '2010-10-27 17:59:06', 'admin'),
            ('XL10', 'U', 'XL10', 3, 0, 'USSD://*101*10000*00*<dest>*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('XL100', 'B', '', 3, 100000, 'USSD://*101*100000*00*<dest>*<pin>#', '2010-10-27 15:47:18', 'admin'),
            ('XL25', 'B', '', 3, 25000, 'USSD://*101*25000*00*<dest>*<pin>#', '2010-10-27 15:47:15', 'admin'),
            ('XL5', 'U', 'XL5', 3, 0, 'USSD://*101*5000*00*<dest>*<pin>#', '2010-10-27 15:42:15', 'admin'),
            ('XL50', 'B', '', 3, 50000, 'USSD://*101*50000*00*<dest>*<pin>#', '2010-10-27 15:47:12', 'admin')''')
        cursor.execute('DELETE FROM `agent`')
        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', ''),
            ('00002', 1, 'Stephanus Ridwan', 'PM', 1, '8888', '00001', 0, 100, 'Test', '2010-11-09 18:24:44', '2010-11-09 18:24:51', '2011-01-12 21:20:01', ''),
            ('00003', 1, 'Dewi Karyana', 'Depok', 1, '0891', '00002', 0, 100, 'Test', '2010-11-09 18:24:51', '2010-11-09 18:24:51', '2011-01-12 21:20:22', '')''')
        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', ''),
            ('00002', 'A10', 10250, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'A5', 5250, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'AP10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'AP5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'AX10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'AX20', 20200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'AX50', 50200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'E25', 25200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'E50', 50200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'F10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'F20', 20200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'F5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'FR10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'FR20', 20200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'FR25', 25200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'H10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'H25', 25200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'H5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'M10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'M5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'S10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'S5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SM10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SM20', 20200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SM5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SO10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SO20', 20200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SO5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SP10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'SP5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'T10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'T20', 20200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'T5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'X10', 10200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00002', 'X5', 5200, 100, NULL, 1, '2011-01-12 21:20:01', ''),
            ('00003', 'A10', 10350, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'A5', 5350, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'AP10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'AP5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'AX10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'AX20', 20300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'AX50', 50300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'E25', 25300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'E50', 50300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'F10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'F20', 20300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'F5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'FR10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'FR20', 20300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'FR25', 25300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'H10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'H25', 25300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'H5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'M10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'M5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'S10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'S5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SM10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SM20', 20300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SM5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SO10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SO20', 20300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SO5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SP10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'SP5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'T10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'T20', 20300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'T5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'X10', 10300, 100, NULL, 1, '2011-01-12 21:20:22', ''),
            ('00003', 'X5', 5300, 100, NULL, 1, '2011-01-12 21:20:22', '')''')
        cursor.execute('''INSERT INTO `deposit_mutation` (`deposit_mutation_id`, `timestamp`, `agent_id`, `mutation`, `type`, `deposit_balance`, `comment`) VALUES
            (1, '2011-01-12 22:00:51', '00001', 100000, 'C', 100000, 'Initial'),
            (2, '2011-01-12 22:01:29', '00002', 150000, 'C', 150000, 'Initial'),
            (3, '2011-01-12 22:01:51', '00003', 120000, 'C', 120000, 'Initial')''')
        cursor.execute('''INSERT INTO `message` (`name`, `description`, `parse`) VALUES
          ('agent_invalid', 'Invalid Agent', 'Agen tidak terdaftar atau PIN salah.'),
          ('agent_not_enough_balance', 'Not Enough Balance', 'Topup <product_id> gagal. Saldo tidak mencukupi. Sisa saldo <balance>.'),
          ('agent_not_frontline', 'Agent is not your downline', 'Agen <agent_id> bukan downline langsung.'),
          ('agent_not_reg', 'Agent not registered', 'Agent <agent_id> tidak terdaftar.'),
          ('amount_not_number', 'Amount transfer is not numeric', '<amount> bukan angka.'),
          ('amount_zero', 'Amount can not be zero', 'Jumlah transfer tidak boleh 0 (nol).'),
          ('change_frontlinemarkup_success', 'Markup Agent', 'Rubah markup agen <agent_id> BERHASIL. Markup baru: <markup>.'),
          ('change_globalmarkup_success', 'Markup Global', 'Rubah markup seluruh downline BERHASIL. Markup baru: <markup>.'),
          ('change_pin', 'Change PIN', 'Ganti PIN sukses. Pin baru adalah <pin>.'),
          ('deposit_level', 'Deposit', 'Deposit: <deposit>.'),
          ('hlr_not_supported', 'HLR Not Supported', 'Nomor tujuan <dest> di luar area kami.'),
          ('markup_is_zero', 'Markup can not be zero', 'Markup harus lebih besar dari 0.'),
          ('markup_not_number', 'Markup is not numeric', 'Markup <markup> bukan angka.'),
          ('num_op_dont_match', 'Operator not match with destination', 'Tujuan <dest> bukan jaringan <operator>.'),
          ('out_of_stock', 'Closed Product', 'Produk <product_id> tidak tersedia.'),
          ('product_price', 'Product Price', 'Harga <product_id>: <price>.'),
          ('prod_not_registered', 'Product not registered', 'Produk <product_id> tidak tersedia.'),
          ('register_new_agent', 'New Agent', 'Agen "<name>" memiliki kode agen: <agent_id>. PIN awal: 1234.'),
          ('topup_fail', 'Top up Fail', 'Topup tidak berhasil, <reason>.'),
          ('transaction_status', 'Transaction Status', 'Topup produk <product_id> untuk <dest> <status>'),
          ('transaction_successful', 'Transaction Report', 'Transaksi <product_id> untuk <dest> BERHASIL. Ref:<ref> saldo <balance>'),
          ('transfer_agent_not_enough_bal', 'Not Enough Balance', 'Saldo agen tidak cukup untuk transfer. Saldo agen <agent_id> <balance>.'),
          ('transfer_fail', 'Transfer Fail', 'Transfer untuk saat ini tidak dapat dilakukan. Cobalah beberapa saat lagi.'),
          ('transfer_not_enough_balance', 'Transfer Not Enough Balance', 'Saldo tidak mencukupi untuk transfer. Saldo anda <balance>.'),
          ('transfer_over_revoke', 'Transfer Over Revoke', 'Tidak bisa mengambil lebih banyak dari transfer harian. Sisa transfer hari ini <transfer>.'),
          ('transfer_status', 'Transfer Status', 'Transfer deposit agen <agent_id>, order ke-<order> sebesar <amount> BERHASIL.'),
          ('unknown_command', 'Unknown Command', 'Perintah tidak dikenal.'),
          ('wrong_req_format', 'Wrong Format', 'Format topup request tidak dikenal.')''')
        cursor.execute('DELETE FROM `regprotocol`')
        cursor.execute('''INSERT INTO `regprotocol` (`reg_protocol`, `agent_id`) VALUES
            ('sms://08161940700', '00001'),
            ('sms://02123881811', '00002'),
            ('ym://sridwan981', '00002'),
            ('sms://02196818889', '00003')''')
        cursor.execute('DELETE FROM `message`')
        cursor.execute('''INSERT INTO `message` (`name`, `description`, `parse`) VALUES
            ('agent_invalid', 'Invalid Agent', 'Agen tidak terdaftar atau PIN salah.'),
            ('agent_not_enough_balance', 'Not Enough Balance', 'Topup <product_id> gagal. Saldo tidak mencukupi. Sisa saldo <balance>.'),
            ('agent_not_frontline', 'Agent is not your downline', 'Agen <agent_id> bukan downline langsung.'),
            ('agent_not_reg', 'Agent not registered', 'Agent <agent_id> tidak terdaftar.'),
            ('amount_not_number', 'Amount transfer is not numeric', '<amount> bukan angka.'),
            ('amount_zero', 'Amount can not be zero', 'Jumlah transfer tidak boleh 0 (nol).'),
            ('change_frontlinemarkup_success', 'Markup Agent', 'Rubah markup agen <agent_id> BERHASIL. Markup baru: <markup>.'),
            ('change_globalmarkup_success', 'Markup Global', 'Rubah markup seluruh downline BERHASIL. Markup baru: <markup>.'),
            ('change_pin', 'Change PIN', 'Ganti PIN sukses. Pin baru adalah <pin>.'),
            ('deposit_level', 'Deposit', 'Deposit: <deposit>.'),
            ('hlr_not_supported', 'HLR Not Supported', 'Nomor tujuan <dest> di luar area kami.'),
            ('markup_is_zero', 'Markup can not be zero', 'Markup harus lebih besar dari 0.'),
            ('markup_not_number', 'Markup is not numeric', 'Markup <markup> bukan angka.'),
            ('num_op_dont_match', 'Operator not match with destination', 'Tujuan <dest> bukan jaringan <operator>.'),
            ('out_of_stock', 'Closed Product', 'Produk <product_id> tidak tersedia.'),
            ('product_price', 'Product Price', 'Harga <product_id>: <price>.'),
            ('prod_not_registered', 'Product not registered', 'Produk <product_id> tidak tersedia.'),
            ('register_new_agent', 'New Agent', 'Agen "<name>" memiliki kode agen: <agent_id>. PIN awal: 1234.'),
            ('topup_fail', 'Top up Fail', 'Topup tidak berhasil, <reason>.'),
            ('transaction_status', 'Transaction Status', 'Topup produk <product_id> untuk <dest> <status>'),
            ('transaction_successful', 'Transaction Report', 'Transaksi <product_id> untuk <dest> BERHASIL. Ref:<ref> saldo <balance>'),
            ('transfer_agent_not_enough_bal', 'Not Enough Balance', 'Saldo agen tidak cukup untuk transfer. Saldo agen <agent_id> <balance>.'),
            ('transfer_fail', 'Transfer Fail', 'Transfer untuk saat ini tidak dapat dilakukan. Cobalah beberapa saat lagi.'),
            ('transfer_not_enough_balance', 'Transfer Not Enough Balance', 'Saldo tidak mencukupi untuk transfer. Saldo anda <balance>.'),
            ('transfer_over_revoke', 'Transfer Over Revoke', 'Tidak bisa mengambil lebih banyak dari transfer harian. Sisa transfer hari ini <transfer>.'),
            ('transfer_status', 'Transfer Status', 'Transfer deposit agen <agent_id>, order ke-<order> sebesar <amount> BERHASIL.'),
            ('unknown_command', 'Unknown Command', 'Perintah tidak dikenal.'),
            ('wrong_req_format', 'Wrong Format', 'Format topup request tidak dikenal.')''')
        self.dbconn.commit()
        cursor.close()
示例#7
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)