# 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()
mysql取随机数据作接口自动化case的入参
最新推荐文章于 2024-03-28 15:50:49 发布