美文网首页软件测试工作笔记
python代码编写接口测试

python代码编写接口测试

作者: 轻情 | 来源:发表于2017-04-09 09:53 被阅读7次

    importrequests

    importjson

    classTools:

    def__init__(self,host=None,scheme=None):

    self.host = host

    self.scheme = scheme

    defapiPostMethod(self, api,payload):

    url ="%s://%s/%s"% (self.scheme,self.host, api)

    headers = {"Content-Type":"application/x-www-form-urlencoded",

    "Accept-Encoding":"gzip",

    "User-Agent":"XXXX",

    }

    r = requests.post(url,headers=headers,data=payload)

    returnr.json()

    defapiGetMethod(self,api,payload,token):

    url ="%s://%s/%s"% (self.scheme,self.host, api,)

    headers = {"Content-Type":"text/html;charset=utf-8",

    "Accept-Encoding":"gzip",

    "User-Agent":"XXXX",

    "Cookie":"token=%s"%token,

    }

    r = requests.get(url,headers=headers,params=payload)

    print"runing time"

    returnr.json()

    if__name__=="__main__":

    t = Tools(host="api.myhaowai.com",scheme="http")

    r = t.apiGetMethod(api="appsite_api/index/login?"

    "devid=75B846BFD9524CD13DF605E437AA9DC0&pcode=021000&pwd=123456&username=18310341518"

    "&version=3.5",payload=None,token=None)

    token1=r["token"]

    printtoken1

    tt = t.apiGetMethod(api="api/weixin/get_follow_list?page=1 ",payload=None,token=token1)

    printtt

    相关文章

      网友评论

        本文标题:python代码编写接口测试

        本文链接:https://www.haomeiwen.com/subject/qjqdattx.html