欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python:接口间数据传递与调用方法

程序员文章站 2023-11-07 20:57:28
如下所示: import requests import unittest import json from pubulic_way.get_token i...

如下所示:

import requests
import unittest
import json
from pubulic_way.get_token import getsession
 
class testlogin(unittest.testcase):
 
  def test_getidentify(self):
    '''调用test_listcollectinfobycreditid(self)响应数据中的taxid参数'''
    result = self.get_listcollectinfobycreditid()
    json_result=json.loads(result)
    p1 = json_result["polygons"][0]["enterprisetaxid"]
    data = {"lyname":"col_wpolygon_3206","id":"8f34969c-ea5e-489c-94bc-37e54ad40660","taxid":p1}
    url = "http://10.17.17.31:8080/landtaxsys/search/getlayeralianame"
    headers = {'content-type': 'application/x-www-form-urlencoded; charset=utf-8'}
    cookies = self.get_cookies()
    r = requests.post(url,data=data,headers=headers,cookies=cookies)
    # print(p1)
    # print(r.status_code)
    # print(r.text)
    # return r.text
    checkpoint = '91320612ma1uycl59u'
    if r.status_code == 200:
      if checkpoint in r.text:
        print('测试结果:passed,断言成功。响应状态码:{}。响应数据【json】:{}'.format(r.status_code,r.text))
      else:
        print('测试结果:failed,断言失败。响应状态码:{}。断言内容为:{}。响应数据【json】:{}'.format(r.status_code,checkpoint,r.text))
    else:
      print('测试结果:failed,接口不通。响应状态码:{}。响应数据【json】:{}'.format(r.status_code,r.text))
 
  def get_listcollectinfobycreditid(self):
    '''获取响应数据中的taxid参数'''
    url = "http://10.17.17.31:8080/landtaxsys/dataedit/listcollectinfobycreditid"
    data = {"start":"1","end":"8","targettaxid":"91320612ma1uycl59u","nearbytaxid":"","swjgdm":"23206","userid":"32060100033"}
    headers = {'content-type': 'application/x-www-form-urlencoded; charset=utf-8'}
    cookies = self.get_cookies()
    r = requests.post(url,data=data,headers=headers,cookies=cookies)
    return r.text
 
  def get_cookies(self):
    cookies = getsession()
    return cookies
 
 
 
 
if __name__ == '__main__':
  unittest.main()
 

以上这篇python:接口间数据传递与调用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。