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

yipeiwu_com6年前Python基础

如下所示:

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:接口间数据传递与调用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python序列化基础知识(json/pickle)

     我们把对象(变量)从内存中变成可存储的过程称之为序列化,比如XML,在Python中叫pickling,在其他语言中也被称之为seria...

简介Python中用于处理字符串的center()方法

 center()方法返回集中在长度宽度的字符串。填充是通过使用specifiedfillchar。默认填充字符是一个空格。 语法 以下是center()方法的语法: st...

纯Python开发的nosql数据库CodernityDB介绍和使用实例

纯Python开发的nosql数据库CodernityDB介绍和使用实例

看看这个logo,有些像python的小蛇吧 。这次介绍的数据库codernityDB是纯python开发的。 先前用了下tinyDB这个本地数据库,也在一个api服务中用了下,一开始...

Windows下的Python 3.6.1的下载与安装图文详解(适合32位和64位)

Windows下的Python 3.6.1的下载与安装图文详解(适合32位和64位)

为什么,这么简单的一个python,我还要特意来写一篇文章呢? 是因为留念下,在使用了Anaconda2和Anaconda3的基础上,现在需安装python3.6.0来做数据分析。...

python 计算积分图和haar特征的实例代码

下面的代码通过积分图计算一张图片的一种haar特征的所有可能的值。初步学习图像处理并尝试写代码,如有错误,欢迎指出。 import cv2 import numpy as np im...