当前位置:网站首页>接口自动化测试-接口间数据依赖问题解决
接口自动化测试-接口间数据依赖问题解决
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()
边栏推荐
- 存储过程的介绍与基本使用
- LeetCode简单题分享(20)
- LED light of single chip microcomputer learning notes
- 现在网上开户安全么?那么网上开户选哪个证券公司?
- Mongodb meets spark (for integration)
- 2022-7-6 Leetcode 977.有序数组的平方
- Clion mingw64 Chinese garbled code
- Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
- 【日常训练--腾讯精选50】231. 2 的幂
- Redis can only cache? Too out!
猜你喜欢
TPG x AIDU | AI leading talent recruitment plan in progress!
如何让join跑得更快?
2022-7-7 Leetcode 844. Compare strings with backspace
Distributed transaction solution
Navicat运行sql文件导入数据不全或导入失败
.net core 关于redis的pipeline以及事务
Evolution of customer service hotline of dewu
2022-7-6 Leetcode 977. Square of ordered array
2022-7-6 初学redis(一)在 Linux 下下载安装并运行 redis
Detr introduction
随机推荐
高等數學---第八章多元函數微分學1
Realize the IP address home display function and number home query
Realbasicvsr test pictures and videos
xshell连接服务器把密钥登陆改为密码登陆
Laravel Form-builder使用
How far can it go to adopt a cow by selling the concept to the market?
TPG x AIDU | AI leading talent recruitment plan in progress!
存储过程的介绍与基本使用
Data refresh of recyclerview
LED light of single chip microcomputer learning notes
postgresql array类型,每一项拼接
Some principles of mongodb optimization
PHP - laravel cache
社会责任·价值共创,中关村网络安全与信息化产业联盟对话网信企业家海泰方圆董事长姜海舟先生
PHP中用下划线开头的变量含义
648. Word replacement: the classic application of dictionary tree
ES日志报错赏析-Limit of total fields
Show the mathematical formula in El table
高等数学---第八章多元函数微分学1
华为镜像地址