mysql取随机数据作接口自动化case的入参

# coding:utf-8
# Author:sun

import json,random,requests,MySQLdb

xxx = MySQLdb.connect('host','user','passwd','db')
cursor = xxx.cursor()
# 下一条返回的是查询结果数
cursor.execute('搜索语句limit 50')
db_responses = cursor.fetchall() # 元组中包含元组,第二个元组里是长整型的数据类似(10193233L,)
arg_teamid = random.sample(db_responses,1)[0][0]
print arg_teamid # 长整型,作为入参的teamid

class GetKnightByTeamId(object):
    """
    通过团队id获取团队骑手id,团队信息和代理商信息
    """
    def __init__(self):
        url_getteaminfo = 'xxxxx'
        payload_teamargs = {
            "soa": {"req": "123"},"iface": "xxxxxx",
            "ver": "1.0","method": "getKnightTeamInfoByTeamId","args": {"arg0": arg_teamid}
        }
        self.response_teaminfo = requests.post(url_getteaminfo,json = payload_teamargs).json() # 字典序列化为json字符串格式
        self.get_teaminfo = json.loads(self.response_teaminfo['result']) # json字符串反序列化为字典

    def get_knightId(self):
        knightId = self.get_teaminfo.get('knightIds','未获取到knightId') # 获取骑手id列表
        return knightId
"""
    def get_teamName(self):
        teamName = self.get_teaminfo.get('teamName','未获取到teamName') # 获取站点id
        return teamName

    def get_agencyId(self):
        agencyId = self.get_teaminfo.get('agencyId','未获取到agencyId')
        return agencyId

    def get_agencyName(self):
        agencyName = self.get_teaminfo.get('agencyName','未获取到agencyName')
        return agencyName
    def get_orgId(self):
        orgId = self.get_teaminfo.get('orgId','未获取到orgId')
        return orgId
"""
print GetKnightByTeamId().get_knightId()






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值