def db_dump(self):
        if len(self.data) == 0:
            return
        cols = mysql_util.get_cols(self.data[0], self.sql_mapping)
        cols_q = mysql_util.stringify_items(cols)
        vals_q = mysql_util.vals_query(self.data, cols)
        q = "INSERT INTO %s %s VALUES %s" % (self.sql_table, cols_q, vals_q)

        try:
            mysql_util.query(q)
        except Exception as e:
            if str(tuple(e)[0]) != "1062":
                print("Exception raised: %s" % e)

        self.data = list()
	def db_dump(self):
		if len(self.data) == 0:
			return
		cols = mysql_util.get_cols(self.data[0], self.sql_mapping)
		cols_q = mysql_util.stringify_items(cols)
		vals_q = mysql_util.vals_query(self.data, cols)
		q = "INSERT INTO %s %s VALUES %s"%(self.sql_table, cols_q, vals_q)

		try:
			mysql_util.query(q)
		except Exception as e:
			if str(tuple(e)[0]) != "1062":
				print("Exception raised: %s"%e)

		self.data = list()
def test_receiptPartfail():
    # 批量扣款:部分请求成功
    mysql_util.clear("settle_receipt_bill", "settle_receipt_bill_biz")
    result = http_util.post(
        "/route/receipt/batch",
        body=req_model.addreceiptparame("s0012017111422263421"))
    assert_util.verify(result,
                       resultCode="4000",
                       resultMsg=u"部分成功",
                       reqSn="s0012017092200000918",
                       systemSourceId="s001",
                       chnId="ch001")
    assert_util.verify(result["receipRestList"][0],
                       state="-2",
                       resultCode="1000",
                       resultMsg=u"订单接收失败:手机号无效:189;",
                       bizId="s0012017111422263421",
                       systemSourceId="s001",
                       chnId="ch001")
    assert_util.verify(result["receipRestList"][1],
                       state="0",
                       resultCode="2001",
                       resultMsg=u"等待收款",
                       bizId="s0012017111422263431",
                       systemSourceId="s001",
                       chnId="ch001")
    sql = mysql_util.query("settle_receipt_bill_biz",
                           req_sn='s0012017092200000918')
    print json.dumps(sql, indent=4, sort_keys=True)
    assert_util.verify(sql[1],
                       ret_code="2001",
                       state="0",
                       biz_id='s0012017111422263431',
                       req_sn='s0012017092200000918')
def test_receiptrotationfail():
    # 单笔代扣轮训处理中接口
    mysql_util.clear("settle_receipt_bill", "settle_receipt_bill_biz")
    result = http_util.post(
        "/route/receipt/single",
        body=req_model.addreceiptstate("s0012017111422263410"))
    assert_util.verify(result,
                       state="0",
                       resultCode="2001",
                       resultMsg=u'等待收款',
                       receiveTime=req_model.current_time,
                       bizId="s0012017111422263410",
                       systemSourceId="s001",
                       chnId="ch001")
    time.sleep(6)
    sql = mysql_util.query(table="settle_receipt_bill_biz",
                           state=0,
                           ret_code=2001,
                           biz_id="s0012017111422263410")
    print json.dumps(sql, indent=4, sort_keys=True)
    assert_util.verify(sql[0],
                       state="0",
                       ret_code="2001",
                       receive_time=req_model.current_time,
                       biz_id="s0012017111422263410",
                       success_amount="0.00")
def test_receiptrotationSuccess():
    # 单笔代扣轮训成功接口
    mysql_util.clear("settle_receipt_bill", "settle_receipt_bill_biz")
    result = http_util.post(
        "/route/receipt/single",
        body=req_model.addreceiptstate("s0012017111422263410"))
    assert_util.verify(result,
                       state="0",
                       resultCode="2001",
                       resultMsg=u'等待收款',
                       receiveTime=req_model.current_time,
                       bizId="s0012017111422263410",
                       systemSourceId="s001",
                       chnId="ch001")
    sql = mysql_util.update("settle_receipt_bill_biz",
                            "account_no=6214830101923232",
                            biz_id="s0012017111422263412")
    sql = mysql_util.update("settle_receipt_bill",
                            "account_no=6214830101923232",
                            biz_id="s0012017111422263412")
    time.sleep(6)
    sql = mysql_util.query(table="settle_receipt_bill_biz",
                           state=1,
                           ret_code=0000,
                           biz_id="s0012017111422263412",
                           ret_info=u"处理成功")
    print json.dumps(sql, indent=4, sort_keys=True)
    assert_util.verify(sql[0],
                       state="1",
                       ret_code="0000",
                       ret_info=u'处理成功',
                       receive_time=req_model.current_time,
                       biz_id="s0012017111422263412")
Exemple #6
0
def test_payment():
    # 单笔代付接口
    mysql_util.clear("settle_payment_bill","settle_payment_bill_biz")
    result = http_util.post("/route/payment/single", body=req_model.addpaymentparame("s0012017111422263320"))
    assert_util.verify(result, state="0", resultCode="2005", resultMsg=u'等待付款', receiveTime=req_model.current_time,bizId="s0012017111422263320", systemSourceId="s001", chnId="ch001")
    sql = mysql_util.query(table="settle_payment_bill_biz",state=0,ret_code=2005)
    #print json.dumps(sql, indent=4, sort_keys=True)
    assert_util.verify(sql[0], state="0", ret_code="2005", ret_info=u'等待付款', receive_time=req_model.current_time,biz_id="s0012017111422263320",success_amount="0.00", system_source_id="s001", chn_id="ch001")
def dump_files(sql_table, dir, map_func):
	# Form a sql connection to use for a large volume of commits
	con = mysql_util.connect()

	# Iterate through all the files in the data directory
	for file in os.listdir(dir):
		filepath = "%s/%s"%(dir, file)
		reader = csv.DictReader(open(filepath))
		for row in reader:
			cols, vals = mysql_util.unzip(map_func(row))
			try:
				mysql_util.query(form_insert_query(sql_table, cols, vals), con=con)
			except Exception as e:
				if str(tuple(e)[0]) != "1062":				# Mysql error 1062 is for a duplicate entry and this will generate a lot
					print "Exception raised: %s"%str(e)
		
		# Delete the file when we're done with it
		os.remove(filepath)
	
	# Close the connection
	con.close()
def test_receiptbatchsuccess():
    # 批量扣款:验证请求成功
    mysql_util.clear("settle_receipt_bill", "settle_receipt_bill_biz")
    result = http_util.post(
        "/route/receipt/batch",
        body=req_model.addreceiptparame("s001201711142226438"))
    assert_util.verify(result,
                       resultCode="0000",
                       resultMsg=u"处理成功",
                       reqSn="s0012017092200000917",
                       systemSourceId="s001",
                       chnId="ch001")
    assert_util.verify(result["receipRestList"][0],
                       state="0",
                       resultCode="2001",
                       resultMsg=u"等待收款",
                       bizId="s0012017111422263413",
                       systemSourceId="s001",
                       chnId="ch001")
    assert_util.verify(result["receipRestList"][1],
                       state="0",
                       resultCode="2001",
                       resultMsg=u"等待收款",
                       bizId="s001201709290021338",
                       systemSourceId="s001",
                       chnId="ch001")
    sql = mysql_util.query("settle_receipt_bill_biz",
                           req_sn='s0012017092200000917')
    print json.dumps(sql, indent=4, sort_keys=True)
    assert_util.verify(sql[0],
                       ret_code=2001,
                       state="0",
                       biz_id='s0012017111422263413',
                       req_sn='s0012017092200000917')
    assert_util.verify(sql[1],
                       ret_code=2001,
                       state="0",
                       biz_id='s001201709290021338',
                       req_sn='s0012017092200000917')
 def init_timestamps(self):
     last_startTime = mysql_util.query("SELECT max(date) as t FROM %s" %
                                       self.sql_table)[0]['t']
     if last_startTime:
         self.last_startTime = int(last_startTime)
         self.next_startTime = int(last_startTime) + self.period
Exemple #10
0
	def init_timestamps(self):
		last_startTime = mysql_util.query("SELECT max(date) as t FROM %s"%self.sql_table)[0]['t']
		if last_startTime:
			self.last_startTime = int(last_startTime)
			self.next_startTime = int(last_startTime) + self.period
	def init_timestamps(self):
		last_startTime = mysql_util.query("SELECT max(timestamp) as t FROM %s"%self.sql_table)[0]['t']
		if last_startTime:
			self.last_startTime = datetime.strftime(last_startTime, "%Y-%m-%d%%20%H%%3A%M%%3A%S")
			next_startTime = last_startTime + timedelta(minutes=1)
			self.next_startTime = datetime.strftime(next_startTime, "%Y-%m-%d%%20%H%%3A%M%%3A%S")