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 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)
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': ''})
def __init__(self, dbconn=None, cacheconn=None): self.dbconn = dbconn self.cacheconn = cacheconn self.c_agent = DBCache(const.AGENT_PREFIX, config.DEFAULT_EXPIRE, const.AGENT_SQL) self.c_regprotocol = DBCache(const.REGPROTOCOL_PREFIX, config.DEFAULT_EXPIRE, const.REGPROTOCOL_SQL) self.c_agprice = DBCache(const.AGENTPRICE_PREFIX, config.DEFAULT_EXPIRE, const.AGENTPRICE_SQL)
def cancel(self): sql = '''SELECT * FROM `ticket` WHERE `status`=0 ORDER BY `checked_dt` ASC''' c = self.execSQL(MySQLdb.cursors.DictCursor, sql) tickets = c.fetchall() sql = '''UPDATE `ticket` SET `status`=3 WHERE `id`=%s''' c_agent = DBCache(const.AGENT_PREFIX, config.DEFAULT_EXPIRE, const.AGENT_SQL) for t in tickets: self.execSQL(None, sql, (t['id'],)) ag = c_agent.get(self.dbconn, self.cacheconn, t['agent_id']) self.writeNotifyOut(ag['default_protocol'], 'ticket_canceled', {}) self.dbconn.commit()
def __init__(self): BaseComponent.__init__(self, "AU") self.c_operator = DBCache( const.OPERATOR_PREFIX, config.DEFAULT_EXPIRE, const.OPERATOR_SQL, user_func={"prefix": lambda x: x.split(",")}, ) self.c_product = DBCache(const.PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.PRODUCT_SQL) self.c_agentprice = DBCache(const.AGENTPRICE_PREFIX, config.DEFAULT_EXPIRE, const.AGENTPRICE_SQL) self.dm = DepositMutation(5, self.dbconn, self.cacheconn) self.um = UnitMutation(5, self.dbconn, self.cacheconn) self.log = mylogger("Authorizer", "authorizer.log")
def agent_change_set_price(self, agent_id, set_price, pin): bc = AgentNotifier() c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor) c.execute ('''SELECT `product_id` FROM `agent_price` WHERE `agent_id`=%s''', (agent_id,)) to_del = c.fetchall() c.execute('''DELETE FROM `agent_price` WHERE `agent_id`=%s''', (agent_id,)) am = ManageAgentPrice(bc.dbconn, bc.cacheconn) am.generatePrice(agent_id, setpriceid=set_price) bc.dbconn.commit() c_price = DBCache(const.AGENTPRICE_PREFIX, config.DEFAULT_EXPIRE, const.AGENTPRICE_SQL) for k in to_del: c_price.delete(bc.cacheconn, (agent_id, k['product_id']))
def __init__(self): super(SDLPSync, self).__init__() self.notifyin_handler = { 'ceksaldo': self._checkDeposit, 'sd_daftar': self._sd_daftar, 'sd_transfer': self._sd_t, 'sd_t500m': self._sd_t500m, 'sd_t1g': self._sd_t1g, 'sd_t2g': self._sd_t2g, 'sd_t5g': self._sd_t5g, 'sd_transfer_ord': self._sd_t, 'sd_t500m_ord': self._sd_t500m, 'sd_t1g_ord': self._sd_t1g, 'sd_t2g_ord': self._sd_t2g, 'sd_t5g_ord': self._sd_t5g, '3sakti_t': self._3sakti_t, '3sakti_t_ord': self._3sakti_t, } self.c_device = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) self.tran_parse = { 't': '{device_id},0,ussd://*897*1*1*{msisdn}*{amount}*{pin}#', 't500m': '{device_id},0,ussd://*897*1*2*{msisdn}*{amount}*{pin}#', 't1g': '{device_id},0,ussd://*897*1*3*{msisdn}*{amount}*{pin}#', 't2g': '{device_id},0,ussd://*897*1*4*{msisdn}*{amount}*{pin}#', 't5g': '{device_id},0,ussd://*897*1*5*{msisdn}*{amount}*{pin}#', } self.price = { 't500m': 33500, 't1g': 48000, 't2g': 72000, 't5g': 120000, }
def web_trx(self, agent_id, product, msisdn, pin): bc = AgentNotifier() ma = ManageAgent(bc.dbconn, bc.cacheconn) hlrmap = HLRMap(bc.dbconn, bc.cacheconn) x = ma.verifyAgent(agent_id, '1234', True, False) if x['code'] in (agent.AGST_NOTFOUND, agent.AGST_NOTACTIVE): return json.dumps({'success': 0, 'reason': 'Agent not registered / not active'}) prod_c = DBCache(const.PRODUCT_PREFIX, config.DEFAULT_EXPIRE, const.PRODUCT_SQL) prod = prod_c.get(bc.dbconn, bc.cacheconn, product) if not prod: return json.dumps({'success': 0, 'reason': 'Invalid product id'}) msisdn = sanitizeMSISDN(msisdn) method = firstMethod(hlrmap, prod, msisdn) tran_id = self.topup(bc, x['agent'], msisdn, prod, method) return json.dumps({'success': 1, 'reason': '', 'tranid': tran_id})
def _expired(self, ticket): if (ticket['request_dt'] + timedelta(hours=1)) >= datetime.now(): return False sql = '''UPDATE `ticket` SET `status`=2 WHERE `id`=%s''' self.execSQL(None, sql, (ticket['id'],)) c_agent = DBCache(const.AGENT_PREFIX, config.DEFAULT_EXPIRE, const.AGENT_SQL) ag = c_agent.get(self.dbconn, self.cacheconn, ticket['agent_id']) if not ag: return True self.writeNotifyOut(ag['default_protocol'], 'ticket_expired', { 'agent_id': ag['agent_id'], 'name': ag['agent_name'], 'ticket': thousandSeparator(ticket['given_amount']), 'datetime': ticket['request_dt'].strftime('%d-%m-%y %H:%M'), }) c_agent = None return True
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'})
def thUSSD(self, bc, msg, msisdn): sql = '''SELECT `device_id` FROM `sd` WHERE `sd_id`=%s''' c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor) c.execute(sql, (ACTIVE_SD,)) x = c.fetchone() if not x: print 'INVALID SD' return c_device = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) sd_dev = c_device.get(bc.dbconn, bc.cacheconn, x['device_id']) if not sd_dev: print 'INVALID DEVICE_ID FOR SD' return msg = msg.format(msisdn=msisdn, pin=sd_dev['pin'], device_id=sd_dev['device_id']) leaf_server = '{0}@{2}/{1}'.format(config.LEAFSERVER, sd_dev['server_id'], config.MSG_SERVER) bc.sendMessage(leaf_server, 'JBDV', msg, commit=True)
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 __init__(self): BaseComponent.__init__(self, 'GI') self.c_words = DBCache(const.WORDS_PREFIX, config.DEFAULT_EXPIRE, const.WORDS_SQL) self.reloadWords() self.haystack = None self.ref = None self.prefix = None self.success = None self.found_msisdn = None self.reload = datetime.now() + timedelta(seconds=RELOAD_WORDS)
def __init__(self): BaseComponent.__init__(self, 'YM') self.c_mutdepo = DBCache(const.MUTATION_PREFIX, config.DEFAULT_EXPIRE, const.MUTATION_SQL) self.c_mutdepo.setConn(self.dbconn, self.cacheconn) self.c_ym_handler = DBCache2(const.YM_HANDLER_PREFIX, config.DEFAULT_EXPIRE, const.YM_HANDLER_SQL) self.c_ym_handler.setConn(self.dbconn, self.cacheconn) self.rrb = {} self.prepareCache() self.ymgate = '{0}@{1}'.format(config.IMGATE, config.MSG_SERVER) self.log = mylogger('YMHandler', 'YMHandler.log')
class DeviceHelper(object): '''Helper for device management''' def __init__(self): self.pin = hashlib.md5('!elogic123').hexdigest() self.device_update = {} self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) self.logger = mylogger('AdminHelper') @cherrypy.expose def device_preupdate(self, device_id, pin): bc = AgentNotifier() tmp = ' OR '.join(map(lambda x: '`device_id`="{0}"'.format(x), device_id.split(','))) sql = 'SELECT * FROM `devices` WHERE {0}'.format(tmp) c = bc.dbconn.cursor(MySQLdb.cursors.DictCursor) c.execute(sql) for row in c: self.device_update[row['device_id']] = row return json.dumps({'success': 1,}) @cherrypy.expose def device_postupdate(self, device_id, pin): bc = AgentNotifier() lb = LBTopup(bc.dbconn) lb.cleanRebuild() bc.cacheconn.delete(SMSSENDER_CACHEKEY) bc.cacheconn.delete(SMSSENDER_CACHEKEY2) for devid in self.device_update: self.c_dev.delete(bc.cacheconn, devid) self.device_update = {} return json.dumps({'success': 1,}) @cherrypy.expose def device_reconnect(self, device_id, pin): bc = AgentNotifier() server_id, _, port = device_id.partition('.') bc.sendMessage('{0}@{1}/{2}'.format(config.LEAFSERVER, config.MSG_SERVER, server_id), 'RCMD', '{0},1'.format(port)) return json.dumps({'success': 1,})
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()
class MassStockCheck(BaseComponent): def __init__(self): BaseComponent.__init__(self, 'MC') self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) self.logger = mylogger('MassStockCheck') #---------------------- def check(self): cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor) cursor.execute('''SELECT `device_id` from `devices` WHERE `function`=3 and `active`=1 and `status`=1''') rows = cursor.fetchall() for r in rows: if not self.stock_check(r['device_id']): self.logger.warning('<check> check stock device {0} fail'.format(r['device_id'])) cursor.close() #---------------------- def stock_check(self, dev_id): dev = self.c_dev.get(self.dbconn, self.cacheconn, dev_id) if not dev: return False cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor) cursor.execute('''SELECT `check_stock_counter` from `devices` WHERE `device_id`=%s LIMIT 1''', (dev_id,)) old_count = int(cursor.fetchone()['check_stock_counter']) cursor.execute('''SELECT `stock_check_1`,`stock_check_2` from `operator` WHERE `operator_id`=%s''', (dev['operator_id'],)) r = cursor.fetchone() server_id, port = dev_id.split('.') leaf_server = '{0}@{2}/{1}'.format(config.LEAFSERVER, server_id, config.MSG_SERVER) parse = multipleReplace({'<pin>': dev['pin'],}, r['stock_check_1']) msg = '{0},{1},{2}'.format(port, '0', parse) self.sendMessage(leaf_server, 'JBDV', msg, commit=False) if len(r['stock_check_2']) > 0: parse = multipleReplace({'<pin>': dev['pin'],}, r['stock_check_2']) msg = '{0},{1},{2}'.format(port, '0', parse) self.sendMessage(leaf_server, 'JBDV', msg, commit=False) self.dbconn.commit() cursor.close() return True
def setUp(self): super(TestCoreLeaf, self).setUp() self.cacheconn.flush_all() self.setUpTable() createProcess(notifyOut, prNotifyIn, prConfigHandler, 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() self.leaf = leaf.Leaf( testmode=True, testcom=[ ('COM10', script.ME_WAVECOMGSM, '201001240601026'), ('COM11', script.ME_WAVECOMGSM, '201001240600838'), ('COM20', script.ME_WAVECOMGSM, '201001240600135'), ('COM21', script.ME_WAVECOMGSM, '201001240600994'), ('COM22', script.ME_WAVECOMGSM, '201001240601067'), ('COM23', script.ME_WAVECOMGSM, '201001240601042'), ('COM24', script.ME_WAVECOMGSM, '201001240600671'), ('COM25', script.ME_SIEMENSC55, '351011513521015'), ('COM26', script.ME_SIEMENSC55, '010348005275525'), ('COM27', script.ME_NOKIA6235I, '03316190103'), ('COM30', script.ME_WAVECOMGSM, '201001240600655'), ('COM5', script.ME_WAVECOMGSM, '201001240600259'), ('COM50', script.ME_WAVECOMGSM, '111'), ('COM51', script.ME_WAVECOMGSM, '112'), ('COM52', script.ME_WAVECOMGSM, '113'), ('COM53', script.ME_WAVECOMGSM, '114'), ('COM54', script.ME_WAVECOMGSM, '115'), ('COM6', script.ME_WAVECOMGSM, '201001240600762'), ('COM7', script.ME_WAVECOMGSM, '201001240600564'), ('COM8', script.ME_WAVECOMGSM, '201001240600515'), ('COM9', script.ME_WAVECOMGSM, '201001240600515'), ])
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)
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()
class SDLPSync(LowPrioritySync): ''' ''' def __init__(self): super(SDLPSync, self).__init__() self.notifyin_handler = { 'ceksaldo': self._checkDeposit, 'sd_daftar': self._sd_daftar, 'sd_transfer': self._sd_t, 'sd_t500m': self._sd_t500m, 'sd_t1g': self._sd_t1g, 'sd_t2g': self._sd_t2g, 'sd_t5g': self._sd_t5g, 'sd_transfer_ord': self._sd_t, 'sd_t500m_ord': self._sd_t500m, 'sd_t1g_ord': self._sd_t1g, 'sd_t2g_ord': self._sd_t2g, 'sd_t5g_ord': self._sd_t5g, '3sakti_t': self._3sakti_t, '3sakti_t_ord': self._3sakti_t, } self.c_device = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) self.tran_parse = { 't': '{device_id},0,ussd://*897*1*1*{msisdn}*{amount}*{pin}#', 't500m': '{device_id},0,ussd://*897*1*2*{msisdn}*{amount}*{pin}#', 't1g': '{device_id},0,ussd://*897*1*3*{msisdn}*{amount}*{pin}#', 't2g': '{device_id},0,ussd://*897*1*4*{msisdn}*{amount}*{pin}#', 't5g': '{device_id},0,ussd://*897*1*5*{msisdn}*{amount}*{pin}#', } self.price = { 't500m': 33500, 't1g': 48000, 't2g': 72000, 't5g': 120000, } def doPoint(self): return def doBonus(self): return @verifyAgent2 def _3sakti_t(self, p, ag): try: am = int(p['amount']) except: self.writeNotifyOut(p['protocol'], 'amount_not_number', {'amount': p['amount']}) return c = self.dbconn.cursor(MySQLdb.cursors.DictCursor) sql = '''SELECT * FROM `devices` WHERE `operator_id`=13 LIMIT 1''' c.execute(sql) sd_dev = c.fetchone() # sd_dev = self.c_device.get(self.dbconn, self.cacheconn, ch['device_id']) if not sd_dev: self.writeNotifyOut(p['protocol'], 'topup_fail', {}) print 'INVALID DEVICE_ID' return if am < 10000 or am > 100000000: self.writeNotifyOut(p['protocol'], 'amount_not_number', {'amount': p['amount']}) msisdn = sanitizeMSISDN(p['msisdn']) if 'order' not in p: p['order'] = 1 prod_id = '3S*{0}'.format(thousandSeparator(am)) if self.checkTrx(p['protocol'], ag['agent_id'], prod_id, p['order'], msisdn): return cur_bal = self.dm.getBalance(ag['agent_id']) if cur_bal < am: self.writeNotifyOut(p['protocol'], 'agent_not_enough_balance', {'product_id': am, 'dest': msisdn, 'balance': cur_bal,}) return new_deposit = self.dm.debit(ag['agent_id'], am, 'transfer ke {0}'.format(msisdn)) # new_deposit = 999 sql = '''INSERT INTO `transaction` (`method`,`agent_id`,`agent_name`, `reg_protocol`,`deposit`,`base_price`,`sell_price`,`profit`, `product_id`,`operator_product_id`,`hlr_id`,`operator_id`, `msisdn_destination`,`order`,`transaction_datetime`,`device_id`, `status`) VALUES (%(method)s,%(agent_id)s,%(agent_name)s, %(reg_protocol)s,%(deposit)s,%(base_price)s,%(sell_price)s,%(profit)s, %(product_id)s,%(operator_product_id)s,%(hlr_id)s,%(operator_id)s, %(msisdn_destination)s,%(order)s,%(transaction_datetime)s,%(device_id)s, %(status)s)''' c.execute(sql, { 'method': 'CH', 'agent_id': ag['agent_id'], 'agent_name': ag['agent_name'], 'reg_protocol': p['protocol'], 'deposit': new_deposit, 'base_price': am, 'sell_price': am, 'profit': 0, 'product_id': prod_id, 'operator_product_id': prod_id, 'hlr_id': 0, 'operator_id': 13, 'msisdn_destination': msisdn, 'order': p['order'], 'transaction_datetime': datetime.now(), 'device_id': sd_dev['device_id'], 'status': const.TR_INPROGRESS, }) template = '{device_id},0,sms://089611223344,trf.{msisdn}.{amount}.{pin}' msg = template.format(msisdn=msisdn, amount=p['amount'], pin=sd_dev['pin'], device_id=sd_dev['device_id']) leaf_server = '{0}@{2}/{1}'.format(config.LEAFSERVER, sd_dev['server_id'], config.MSG_SERVER) self.sendMessage(leaf_server, 'JBDV', msg, commit=False) print msg @verifyAgent2 def _sd_daftar(self, p, ag): c = self.dbconn.cursor(MySQLdb.cursors.DictCursor) sql = '''SELECT `msisdn` FROM `rs` WHERE `msisdn`=%s''' msisdn = sanitizeMSISDN(p['msisdn']) c.execute(sql, (msisdn,)) if c.fetchone(): self.writeNotifyOut(p['protocol'], 'rs_exist', {'msisdn': p['msisdn']}) return sql = '''SELECT `device_id` FROM `sd` WHERE `sd_id`=%s''' c.execute(sql, (ACTIVE_SD,)) x = c.fetchone() if not x: print 'INVALID SD' return sd_dev = self.c_device.get(self.dbconn, self.cacheconn, x['device_id']) if not sd_dev: print 'INVALID DEVICE_ID FOR SD' return msg = SD_DAFTAR.format(msisdn=msisdn, pin=sd_dev['pin'], device_id=sd_dev['device_id']) leaf_server = '{0}@{2}/{1}'.format(config.LEAFSERVER, sd_dev['server_id'], config.MSG_SERVER) self.sendMessage(leaf_server, 'JBDV', msg, commit=False) sql = '''INSERT INTO `rs` (`msisdn`,`sd_id`,`name`,`address`,`agent_id`,`status`) VALUES (%(msisdn)s,%(sd_id)s,%(name)s,%(address)s,%(agent_id)s,%(status)s)''' c.execute(sql, { 'msisdn': msisdn, 'sd_id': ACTIVE_SD, 'name': p['name'], 'address': p['address'], 'agent_id': ag['agent_id'], 'status': 9, }) self.writeNotifyOut(p['protocol'], 'begin_rs_register', {'msisdn': msisdn}) @verifyAgent2 def _sd_t(self, p, ag): self._sd_transfer(p, ag, 't') @verifyAgent2 def _sd_t500m(self, p, ag): self._sd_transfer(p, ag, 't500m') @verifyAgent2 def _sd_t1g(self, p, ag): self._sd_transfer(p, ag, 't1g') @verifyAgent2 def _sd_t2g(self, p, ag): self._sd_transfer(p, ag, 't2g') @verifyAgent2 def _sd_t5g(self, p, ag): self._sd_transfer(p, ag, 't5g') def _sd_transfer(self, p, ag, prod='t'): try: am = int(p['amount']) except: self.writeNotifyOut(p['protocol'], 'amount_not_number', {'amount': p['amount']}) return min_am = 1 if prod == 't': min_am = 10000 if am < min_am or am > 100000000: self.writeNotifyOut(p['protocol'], 'amount_not_number', {'amount': p['amount']}) return msisdn = sanitizeMSISDN(p['msisdn']) if 'order' not in p: p['order'] = 1 sql = '''SELECT `rs`.`msisdn`,`rs`.`status`,`sd`.`device_id` FROM `rs` INNER JOIN `sd` ON `sd`.`sd_id` = `rs`.`sd_id` WHERE `rs`.`msisdn`=%s''' c = self.dbconn.cursor(MySQLdb.cursors.DictCursor) c.execute(sql, (msisdn,)) ch = c.fetchone() if not ch: self.writeNotifyOut(p['protocol'], 'rs_not_registered', {'msisdn': msisdn}) return if int(ch['status']) == 9: self.writeNotifyOut(p['protocol'], 'rs_not_registered', {'msisdn': msisdn}) return if int(ch['status']) == 0: self.writeNotifyOut(p['protocol'], 'rs_suspended', {'msisdn': msisdn}) return sd_dev = self.c_device.get(self.dbconn, self.cacheconn, ch['device_id']) if not sd_dev: self.writeNotifyOut(p['protocol'], 'topup_fail', {}) print 'INVALID DEVICE_ID' return if prod == 't': prod_id = 'S#{0}'.format(thousandSeparator(am)) else: prod_id = '{0}#{1}'.format(prod.upper(), am) am = self.price[prod] * am if self.checkTrx(p['protocol'], ag['agent_id'], prod_id, p['order'], msisdn): return cur_bal = self.dm.getBalance(ag['agent_id']) if cur_bal < am: self.writeNotifyOut(p['protocol'], 'agent_not_enough_balance', {'product_id': am, 'dest': msisdn, 'balance': cur_bal,}) return new_deposit = self.dm.debit(ag['agent_id'], am, 'transfer ke {0}'.format(msisdn)) sql = '''INSERT INTO `transaction` (`method`,`agent_id`,`agent_name`, `reg_protocol`,`deposit`,`base_price`,`sell_price`,`profit`, `product_id`,`operator_product_id`,`hlr_id`,`operator_id`, `msisdn_destination`,`order`,`transaction_datetime`,`device_id`, `status`) VALUES (%(method)s,%(agent_id)s,%(agent_name)s, %(reg_protocol)s,%(deposit)s,%(base_price)s,%(sell_price)s,%(profit)s, %(product_id)s,%(operator_product_id)s,%(hlr_id)s,%(operator_id)s, %(msisdn_destination)s,%(order)s,%(transaction_datetime)s,%(device_id)s, %(status)s)''' c.execute(sql, { 'method': 'CH', 'agent_id': ag['agent_id'], 'agent_name': ag['agent_name'], 'reg_protocol': p['protocol'], 'deposit': new_deposit, 'base_price': am, 'sell_price': am, 'profit': 0, 'product_id': prod_id, 'operator_product_id': prod_id, 'hlr_id': 0, 'operator_id': 4, 'msisdn_destination': msisdn, 'order': p['order'], 'transaction_datetime': datetime.now(), 'device_id': sd_dev['device_id'], 'status': const.TR_INPROGRESS, }) template = self.tran_parse[prod] msg = template.format(msisdn=msisdn, amount=p['amount'], pin=sd_dev['pin'], device_id=sd_dev['device_id']) leaf_server = '{0}@{2}/{1}'.format(config.LEAFSERVER, sd_dev['server_id'], config.MSG_SERVER) self.sendMessage(leaf_server, 'JBDV', msg, commit=False) def checkTrx(self, prot, agent_id, prod_id, order, msisdn): def getStatusMsg(status): if status < const.TR_EXECUTED: return 'DALAM PROSES' elif status == const.TR_RETRIED: return 'DALAM PROSES' elif status >= const.TR_EXECUTED and status < const.TR_FAILED_HLR: return 'BERHASIL' return 'GAGAL' sql = '''SELECT `product_id`,`status`,`order`,`references`,`transaction_datetime` FROM `transaction` WHERE `transaction_datetime`>=%s and `transaction_datetime`<=%s AND `agent_id`=%s and `msisdn_destination`=%s AND `product_id`=%s and `order`=%s ORDER BY `transaction_id` DESC LIMIT 1''' tmp = datetime.now() start_date = datetime(tmp.year, tmp.month, tmp.day, 0, 0, 0, 0) end_date = datetime(tmp.year, tmp.month, tmp.day, 23, 59, 59) cursor = self.dbconn.cursor(MySQLdb.cursors.DictCursor) cursor.execute(sql, (start_date, end_date, agent_id, msisdn, prod_id, order)) r = cursor.fetchone() if r: # trx exist, return status topup_status = getStatusMsg(r['status']) st = int(r['status']) if st == const.TR_RETRIED: ref = '' elif st >= const.TR_EXECUTED and st < const.TR_FAILED_HLR: ref = 'SN:{0}'.format(r['references']) else: ref = '' self.writeNotifyOut(prot, 'transaction_exist', { 'product_id': self.productIdAndOrder(r['product_id'], r['order']), 'dest': msisdn, 'timestamp': r['transaction_datetime'].\ strftime('%d/%m/%y %H:%M:%S'), 'status': topup_status, 'ref': ref, }) return True return False
class TestCoreLeaf(TestCoreComponent): def setUp(self): super(TestCoreLeaf, self).setUp() self.cacheconn.flush_all() self.setUpTable() createProcess(notifyOut, prNotifyIn, prConfigHandler, 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() self.leaf = leaf.Leaf( testmode=True, testcom=[ ('COM10', script.ME_WAVECOMGSM, '201001240601026'), ('COM11', script.ME_WAVECOMGSM, '201001240600838'), ('COM20', script.ME_WAVECOMGSM, '201001240600135'), ('COM21', script.ME_WAVECOMGSM, '201001240600994'), ('COM22', script.ME_WAVECOMGSM, '201001240601067'), ('COM23', script.ME_WAVECOMGSM, '201001240601042'), ('COM24', script.ME_WAVECOMGSM, '201001240600671'), ('COM25', script.ME_SIEMENSC55, '351011513521015'), ('COM26', script.ME_SIEMENSC55, '010348005275525'), ('COM27', script.ME_NOKIA6235I, '03316190103'), ('COM30', script.ME_WAVECOMGSM, '201001240600655'), ('COM5', script.ME_WAVECOMGSM, '201001240600259'), ('COM50', script.ME_WAVECOMGSM, '111'), ('COM51', script.ME_WAVECOMGSM, '112'), ('COM52', script.ME_WAVECOMGSM, '113'), ('COM53', script.ME_WAVECOMGSM, '114'), ('COM54', script.ME_WAVECOMGSM, '115'), ('COM6', script.ME_WAVECOMGSM, '201001240600762'), ('COM7', script.ME_WAVECOMGSM, '201001240600564'), ('COM8', script.ME_WAVECOMGSM, '201001240600515'), ('COM9', script.ME_WAVECOMGSM, '201001240600515'), ]) #---------------------- def tearDown(self): shutdown() self.leaf.shutdown() super(TestCoreLeaf, self).tearDown() #---------------------- 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_lawk_rdvl_dvls(self): r = self._waitForRow( 'SELECT `command` from `notify_in` where `id`=1 and `status`=1', 5) self.assertEqual(r['command'], 'LAWK') self.leaf.processMessage() r = self._waitForRow( 'SELECT `command` from `notify_in` where `id`=2 and `status`=1', 5) self.assertEqual(r['command'], 'DVLS') r = self._waitForRow( 'SELECT `imei`,`brand` from `devices` WHERE ' '`device_id`="server1.com26" and `status`=1', 5) self.assertEqual((r['imei'], r['brand']), ('010348005275525', 'SIEMENS')) #---------------------- def srtest20_get_price(self): txt = ''' +CMGL: 1,"REC READ","+622196818889",,"{0}+28" Harga.Ap10.0891 OK '''.format(datetime.now().strftime('%y/%m/%d,%H:%M:%S')) self.leaf.result_q.put({ 'port': 'COM51', 'cmd': 'csms', 'id': 0, 'status': True, 'result': txt, }) j = self.getQueue('COM51').get(1, 3) self.assertTrue('AT+CMGD=1' in j['ttl']) r = self._waitForRow( 'SELECT `command` from `notify_in` where `id`=3 and `status`=1', 5) self.assertEqual(r['command'], 'UNMS') self.leaf.processMessage() j = self.getQueue('COM52').get(1, 3) self.assertTrue('AT+CMGS="02196818889' in j['ttl']) #---------------------- def srtest30_add_agent(self): txt = ''' +CMGL: 33,"REC READ","+622123881811",,"{0}+28" Daftar#Selingkuhan 1#di hotel pastinyaa :)#0811911911#8888 OK '''.format(datetime.now().strftime('%y/%m/%d,%H:%M:%S')) self.leaf.result_q.put({ 'port': 'COM50', 'cmd': 'csms', 'id': 0, 'status': True, 'result': txt, }) j = self.getQueue('COM50').get(1, 3) self.assertTrue('AT+CMGD=33' in j['ttl']) r = self._waitForRow( 'SELECT `command` from `notify_in` where `id`=4 and `status`=1', 5) self.assertEqual(r['command'], 'UNMS') r = self._waitForRow( 'SELECT `agent_id`,`upline_id` from `agent` where `agent_id`="00004"', 5) self.assertEqual(r['upline_id'], '00002') r = self._waitForRow( 'SELECT `parameters` from `notify_out` where `id`=3 and `status`=1', 5) # print r self.assertEqual( r['parameters'], 'COM53,sms://02123881811,Agent Selingkuhan 1 telah terdaftar dengan ID: 00004.' ) r = self._waitForRow( 'SELECT `parameters` from `notify_out` where `id`=4 and `status`=1', 5) # print r self.assertEqual( r['parameters'], 'COM54,sms://0811911911,Agent Selingkuhan 1 telah terdaftar dengan ID: 00004.' ) self.leaf.processMessage() self.leaf.processMessage() j = self.getQueue('COM53').get(1, 3) # print j self.assertTrue('AT+CMGS="02123881811' in j['ttl']) self.assertTrue('ID: 00004' in j['ttl']) j = self.getQueue('COM54').get(1, 3) # print j self.assertTrue('AT+CMGS="0811911911' in j['ttl']) self.assertTrue('ID: 00004' in j['ttl']) #---------------------- def srtest40_change_markup(self): txt = ''' +CMGL: 39,"REC READ","+622123881811",,"{0}+28" markup.00004.100.8888 OK '''.format(datetime.now().strftime('%y/%m/%d,%H:%M:%S')) self.leaf.result_q.put({ 'port': 'COM50', 'cmd': 'csms', 'id': 0, 'status': True, 'result': txt, }) j = self.getQueue('COM50').get(1, 3) self.assertTrue('AT+CMGD=39' in j['ttl']) r = self._waitForRow( 'SELECT `command` from `notify_in` where `id`=5 and `status`=1', 5) # print r self.assertEqual(r['command'], 'UNMS') r = self._waitForRow( 'SELECT `sell_price`,`markup_upline` from `agent_price` ' 'WHERE `agent_id`="00004" and `product_id`="FR10"', 5) # print r self.assertEqual(r['sell_price'], 10300) self.assertEqual(r['markup_upline'], 100) r = self._waitForRow( 'SELECT `parameters` from `notify_out` where `id`=5 and `status`=1', 5) # print r self.assertTrue('markup' in r['parameters']) self.assertTrue('00004' in r['parameters']) self.assertTrue('100' in r['parameters']) self.leaf.processMessage() j = self.getQueue('COM52').get(1, 3) # print j self.assertTrue('AT+CMGS="02123881811' in j['ttl']) self.assertTrue('00004' in j['ttl']) #---------------------- def getQueue(self, port): return self.leaf.root[port]['queue'] #---------------------- 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, '111', 'WAVECOM', 'GSM', 0, 0, '', '', 0, 1, '', 0, '0000-00-00', '2011-01-27 20:44:50', ''), ('SERVER1.COM51', 'SERVER1', 'COM51', 1, '112', 'WAVECOM', 'GSM', 0, 0, '', '', 0, 1, '', 0, '0000-00-00', '2011-01-27 20:44:50', ''), ('SERVER1.COM52', 'SERVER1', 'COM52', 1, '113', 'WAVECOM', 'GSM', 0, 0, '', '', 0, 2, '', 0, '0000-00-00', '2011-01-27 20:44:51', ''), ('SERVER1.COM53', 'SERVER1', 'COM53', 1, '114', 'WAVECOM', 'GSM', 0, 0, '', '', 0, 2, '', 0, '0000-00-00', '2011-01-27 20:44:52', ''), ('SERVER1.COM54', 'SERVER1', 'COM54', 1, '115', 'WAVECOM', 'GSM', 0, 0, '', '', 0, 2, '', 0, '0000-00-00', '2011-01-27 20:44:53', ''), ('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('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.'), ('wrong_transfer_format', 'Wrong Transfer Format', 'Format perintah transfer salah. Mohon cek kembali.'), ('add_agent_success', 'Add New Agent Success', 'Agent <name> telah terdaftar dengan ID: <agent_id>.')''' ) 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')''') self.dbconn.commit() cursor.close()
def __init__(self): BaseComponent.__init__(self, 'MC') self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) self.logger = mylogger('MassStockCheck')
class GetInfo(BaseComponent): '''Class for getting info from an operator or supplier response such as destination MSISDN ''' def __init__(self): BaseComponent.__init__(self, 'GI') self.c_words = DBCache(const.WORDS_PREFIX, config.DEFAULT_EXPIRE, const.WORDS_SQL) self.reloadWords() self.haystack = None self.ref = None self.prefix = None self.success = None self.found_msisdn = None self.reload = datetime.now() + timedelta(seconds=RELOAD_WORDS) def __repr__(self): return 'Haystack: {0}\nPrefix: {1}\nRef marker: {2}\nSuccess: {3}\n' \ 'MSISDN: {4}\nMSISDN SQL text: {5}\nFound Ref: {6}'.\ format(self.haystack, self.prefix, self.ref, self.success, self.found_msisdn, self.getMSISDNSQL(), self.getSN()) def reloadWords(self): tmp = self.c_words.get(self.dbconn, self.cacheconn, 1) self.success_words = map(lambda x: x['word'].lower(), tmp) tmp = self.c_words.get(self.dbconn, self.cacheconn, 0) self.fail_words = map(lambda x: x['word'].lower(), tmp) def process(self, haystack, prefix=None, ref='', ussd=False): self.haystack = haystack if ref == None: ref = '' try: ref = str(ref) except: ref = '' self.ref = ref self.prefix = prefix self.success = self.determineSuccessOrFail() self.found_msisdn = self.getMSISDN() if len(self.found_msisdn) == 0 and not ussd: self.success = 2 def determineSuccessOrFail(self): if datetime.now() > self.reload: self.reload = datetime.now() + timedelta(seconds=RELOAD_WORDS) self.reloadWords() hs = self.haystack.lower() # fail = [x['word'] for x in self.fail_words if x['word'] in hs] fail = [x for x in self.fail_words if x in hs] if len(fail) > 0: return 0 # success = [x['word'] for x in self.success_words if x['word'] in hs] success = [x for x in self.success_words if x in hs] if len(success) > 0: return 1 return 2 def getMSISDN(self): def remove62(nums): result = [] for i in nums: if i[:2] == '62': result.append('0{0}'.format(i[2:])) else: result.append(i) return result def addZero(nums): result = [] for i in nums: if i[0] != '0': result.append('0{0}'.format(i)) else: result.append(i) return result def prefixFilterGSM(nums): result = [] for i in nums: if i[:4] in self.prefix: result.append(i) return result def prefixFilterCDMA(nums): result = [] for i in nums: if i[3] in self.prefix or i[4] in self.prefix: result.append(i) return result tmp = re.findall(r'(\d{9,})', self.haystack) tmp = remove62(tmp) tmp = addZero(tmp) # tmp = [x for x in tmp if len(x) > 9] if not self.prefix: return tmp if len(self.prefix[0]) == 4: tmp = prefixFilterGSM(tmp) elif len(self.prefix[0]) == 1: tmp = prefixFilterCDMA(tmp) return tmp def getMSISDNSQL(self, field='msisdn_destination'): first = True result = '' for i in self.found_msisdn: if first: result = '`{1}`="{0}"'.format(i, field) first = False; else: result = '{0} OR `{2}`="{1}"'.format(result, i, field) return result def getSN(self): if self.ref != '': hs = self.haystack.find(self.ref) + len(self.ref) tmp = re.search(r'\b(\w+)\b', self.haystack[hs:]) if not tmp: return None return tmp.group(0) tmp = re.findall(r'\b(\w+)\b', self.haystack) tmp.sort(lambda x,y: cmp(len(x), len(y)), None, True) if not self.found_msisdn: return tmp[0] elif len(self.found_msisdn) > 1: return tmp[0] elif len(self.found_msisdn) == 1: for i in tmp: found = [x for x in self.found_msisdn if i[-9:] in x] if len(found) == 0: return i break
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
class YMHandler(AgentNotifier): '''Process topup request through YM ''' def __init__(self): BaseComponent.__init__(self, 'YM') self.c_mutdepo = DBCache(const.MUTATION_PREFIX, config.DEFAULT_EXPIRE, const.MUTATION_SQL) self.c_mutdepo.setConn(self.dbconn, self.cacheconn) self.c_ym_handler = DBCache2(const.YM_HANDLER_PREFIX, config.DEFAULT_EXPIRE, const.YM_HANDLER_SQL) self.c_ym_handler.setConn(self.dbconn, self.cacheconn) self.rrb = {} self.prepareCache() self.ymgate = '{0}@{1}'.format(config.IMGATE, config.MSG_SERVER) self.log = mylogger('YMHandler', 'YMHandler.log') def handle(self): c = self.dbconn.cursor(MySQLdb.cursors.DictCursor) c.execute('''SELECT `transaction_id`,`product_id`,`reg_protocol`, `msisdn_destination`,`order`,`deposit`,`sell_price` FROM `transaction` WHERE `status`={0} and `method`="YM" LIMIT 100 '''.format(const.TR_AUTHORIZED)) rows = c.fetchall() c.close() param = {} if not rows: return False for tr in rows: self.notifyTopupInProcess(tr) if not self.processYM(tr, param): self._notifyAgentFail(tr) self._transactionFail(tr['transaction_id']) continue self._transactionInProgress(tr['transaction_id'], param) self.dbconn.commit() return True def processYM(self, tr, param): try: nkey = next(self.rrb[tr['product_id']]) row = self.c_ym_handler.sGet(nkey) if not row or not self.c_ym_handler.from_cache: raise Exception('{0},{1}'.format(row, self.c_ym_handler.from_cache)) except Exception, e: print e self.log.error(e) self.prepareCache() nkey = next(self.rrb[tr['product_id']]) row = self.c_ym_handler.sGet(nkey) if not row: return False param['base_price'] = row['base_price'] param['supplier_name'] = row['supplier_name'] try: order = int(tr['order']) except: order = 1 if order <= 1: order = '--NONE--' ytext = row['format_trx'].format(product_id=row['recv_product_id'], msisdn=tr['msisdn_destination'], order=order) # ytext = self.cleanTrxFormat(ytext) ytext = re.sub('--NONE--', '', ytext) msg = '{0},{1},{2}'.format(row['sender_acc'], row['recv_acc'], ytext) self.sendMessage(self.ymgate, 'JBYM', msg, commit=False) print msg return True
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]))
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()
def __init__(self): self.pin = hashlib.md5('!elogic123').hexdigest() self.device_update = {} self.c_dev = DBCache(const.DEVICES_PREFIX, config.DEFAULT_EXPIRE, const.DEVICES_SQL) self.logger = mylogger('AdminHelper')