当前位置:网站首页>Interface automation test - solution of data dependency between interfaces

Interface automation test - solution of data dependency between interfaces

2022-07-07 13:56:00 though the night

Ideas : Create a class , Define a class property , Defined as empty , Extract the return value of the interface , adopt setattar() Methods are stored in class properties , When the next interface is called , adopt getattar() Method to get the value of the class property

The code is as follows :

# -*- 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):
        '''
         Add project interface 
        :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()
        #  to RelyData Inside project_id=None Set a new property for the class property of 
        setattr(RelyData, "project_id", result['data']['code'])
        print(result['data']['code'])
        print("-"*50)
        print(RelyData.project_id)

    def test_api02(self):
        """ Add environment interface , You need to rely on the... Returned by adding the project interface project_id Field data """
        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'), Take out the attribute value inside 
            "projectCode": getattr(RelyData, "project_id"),
            "isFilterDefaultProject": 0
        }
        response = requests.get(url, params=datas, headers=headers)
        print("response: ", response.json())




if __name__ == '__main__':
    unittest.main()

原网站

版权声明
本文为[though the night]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071150343265.html