当前位置:网站首页>接口自动化测试-接口间数据依赖问题解决
接口自动化测试-接口间数据依赖问题解决
2022-07-07 11:51:00 【though the night】
思路:创建类,定义一个类属性,定义为空,提取接口的返回值,通过setattar()方法存储到类属性里,下一个接口调用时,通过getattar()方法获取类属性的值
代码如下:
# -*- coding: utf-8 -*-
# @Time : 2022/7/6
# @Author : dyf
# @FileName: test_api01.py
import unittest
import requests
class RelyData:
project_id = None
class TestApi(unittest.TestCase):
def setUp(self):
pass
def test_api01(self):
'''
添加项目接口
:return:
'''
url = "http://hy.gcjs.zdvictory.com/unionpro/unionpro/v-api/findByCode"
headers = {'Content-Type': 'application/json'}
datas = {"code": "2020-441621-05-01-010932"}
response = requests.post(url, params=datas, headers=headers)
print("response: ", response.json())
result = response.json()
# 给RelyData里面的project_id=None的类属性设置新的属性
setattr(RelyData, "project_id", result['data']['code'])
print(result['data']['code'])
print("-"*50)
print(RelyData.project_id)
def test_api02(self):
"""添加环境接口,需依赖添加项目接口返回的project_id字段数据"""
url = "http://hy.gcjs.zdvictory.com/unionpro/unionpro/v-api/findByProjectCode"
headers = {'Content-Type': 'application/json'}
print(getattr(RelyData, "project_id"))
datas = {
# getattr(RelyData,'project_id'),取出里面的属性值
"projectCode": getattr(RelyData, "project_id"),
"isFilterDefaultProject": 0
}
response = requests.get(url, params=datas, headers=headers)
print("response: ", response.json())
if __name__ == '__main__':
unittest.main()
边栏推荐
- Data refresh of recyclerview
- Clion mingw64 Chinese garbled code
- 2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
- Realize the IP address home display function and number home query
- Evolution of customer service hotline of dewu
- Build a secure and trusted computing platform based on Kunpeng's native security
- xshell连接服务器把密钥登陆改为密码登陆
- Ways to improve the performance of raspberry pie
- Esp32 ① compilation environment
- move base参数解析及经验总结
猜你喜欢
AI人才培育新思路,这场直播有你关心的
2022-7-6 Leetcode 977. Square of ordered array
室内ROS机器人导航调试记录(膨胀半径的选取经验)
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
DID登陆-MetaMask
Evolution of customer service hotline of dewu
[dark horse morning post] Huawei refutes rumors about "military master" Chen Chunhua; Hengchi 5 has a pre-sale price of 179000 yuan; Jay Chou's new album MV has played more than 100 million in 3 hours
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?
xshell连接服务器把密钥登陆改为密码登陆
QQ medicine, Tencent ticket
随机推荐
Cmake learning and use notes (1)
【等保】云计算安全扩展要求关注的安全目标和实现方式区分原则有哪些?
566. Reshaping the matrix
Talk about pseudo sharing
C语言数组相关问题深度理解
flask session伪造之hctf admin
118. Yanghui triangle
[daily training -- Tencent select 50] 231 Power of 2
PostgreSQL array type, each splice
Oracle advanced (V) schema solution
2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers
Flink | 多流转换
供应链供需预估-[时间序列]
Final review notes of single chip microcomputer principle
Server to server (S2S) event (adjust)
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
Read PG in data warehouse in one article_ stat
118. 杨辉三角
DID登陆-MetaMask
Leecode3. Longest substring without repeated characters