当前位置:网站首页>接口自动化测试-接口间数据依赖问题解决
接口自动化测试-接口间数据依赖问题解决
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()
边栏推荐
- Use of polarscatter function in MATLAB
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- LeetCode简单题分享(20)
- DID登陆-MetaMask
- PHP中用下划线开头的变量含义
- Flink | 多流转换
- Build a secure and trusted computing platform based on Kunpeng's native security
- 118. Yanghui triangle
- 数字ic设计——SPI
- 648. Word replacement: the classic application of dictionary tree
猜你喜欢
随机推荐
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)
clion mingw64中文乱码
Final review notes of single chip microcomputer principle
648. 单词替换 : 字典树的经典运用
118. 杨辉三角
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
Deep understanding of array related problems in C language
Summary of import, export, backup and recovery of mongodb
OSI seven layer model
2022-7-6 beginner redis (I) download, install and run redis under Linux
Milkdown control icon
Excerpt from "misogyny: female disgust in Japan"
SSRF漏洞file伪协议之[网鼎杯 2018]Fakebook1
Clion mingw64 Chinese garbled code
Esp32 construction engineering add components
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
现在网上开户安全么?那么网上开户选哪个证券公司?
Redis只能做缓存?太out了!
Split screen bug notes
"New red flag Cup" desktop application creativity competition 2022









