当前位置:网站首页>接口自动化测试-接口间数据依赖问题解决
接口自动化测试-接口间数据依赖问题解决
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()
边栏推荐
- Fast development board pinctrl and GPIO subsystem experiment for itop-imx6ull - modify the device tree file
- Leecode3. Longest substring without repeated characters
- Signal strength (RSSI) knowledge sorting
- ES日志报错赏析-Limit of total fields
- Distributed transaction solution
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- 【日常训练--腾讯精选50】231. 2 的幂
- THINKPHP框架的优秀开源系统推荐
- Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
- 社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
猜你喜欢
. Net core about redis pipeline and transactions
Enregistrement de la navigation et de la mise en service du robot ROS intérieur (expérience de sélection du rayon de dilatation)
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
实现IP地址归属地显示功能、号码归属地查询
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
Digital IC Design SPI
记一次 .NET 某新能源系统 线程疯涨 分析
Esp32 construction engineering add components
Deep understanding of array related problems in C language
Use of polarscatter function in MATLAB
随机推荐
The delivery efficiency is increased by 52 times, and the operation efficiency is increased by 10 times. See the compilation of practical cases of financial cloud native technology (with download)
Redis can only cache? Too out!
User management summary of mongodb
PC端页面如何调用QQ进行在线聊天?
记一次 .NET 某新能源系统 线程疯涨 分析
cmake 学习使用笔记(一)
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
How to make join run faster?
Build a secure and trusted computing platform based on Kunpeng's native security
室内ROS机器人导航调试记录(膨胀半径的选取经验)
1. Deep copy 2. Call apply bind 3. For of in differences
属性关键字Aliases,Calculated,Cardinality,ClientName
参数关键字Final,Flags,Internal,映射关键字Internal
Cmake learning and use notes (1)
Detr introduction
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Data refresh of recyclerview
Help tenants
[daily training -- Tencent select 50] 231 Power of 2