当前位置:网站首页>接口自动化测试-接口间数据依赖问题解决
接口自动化测试-接口间数据依赖问题解决
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()
边栏推荐
- Help tenants
- Simple and easy-to-use code specification
- 单片机学习笔记之点亮led 灯
- Realbasicvsr test pictures and videos
- PHP中用下划线开头的变量含义
- What are the principles for distinguishing the security objectives and implementation methods that cloud computing security expansion requires to focus on?
- 现在网上开户安全么?那么网上开户选哪个证券公司?
- Read PG in data warehouse in one article_ stat
- 2022-7-6 Leetcode27.移除元素——太久没有做题了,为双指针如此狼狈的一天
- PC端页面如何调用QQ进行在线聊天?
猜你喜欢

JS slow motion animation principle teaching (super detail)

566. 重塑矩阵

Esp32 ① compilation environment

高等數學---第八章多元函數微分學1

Talk about pseudo sharing

数据库系统概论-第一章绪论【概念模型、层次模型和三级模式(外模式、模式、内模式)】

Dry goods | summarize the linkage use of those vulnerability tools

Use of polarscatter function in MATLAB

Ogre introduction

Redis can only cache? Too out!
随机推荐
10 pictures open the door of CPU cache consistency
[daily training] 648 Word replacement
数字ic设计——SPI
ES日志报错赏析-Limit of total fields
Excerpt from "misogyny: female disgust in Japan"
高等数学---第八章多元函数微分学1
Learning breakout 2 - about effective learning methods
C语言数组相关问题深度理解
[daily training -- Tencent select 50] 231 Power of 2
mysql 局域网内访问不到的问题
User management summary of mongodb
2022-7-7 Leetcode 844.比较含退格的字符串
JS function returns multiple values
OSI seven layer model
Redis只能做缓存?太out了!
Social responsibility · value co creation, Zhongguancun network security and Information Industry Alliance dialogue, wechat entrepreneur Haitai Fangyuan, chairman Mr. Jiang Haizhou
Read PG in data warehouse in one article_ stat
内存溢出和内存泄漏的区别
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
flask session伪造之hctf admin