zoukankan      html  css  js  c++  java
  • Python-DDT实现接口自动化

    Get请求参数化例子

    import unittest
    import requests
    import ddt
    
    
    @ddt.ddt
    class MyTestCase(unittest.TestCase):
        @ddt.data(('qq_37616069', '80376776'), ('zhangchangbin123', '89310491'))
        @ddt.unpack
        def testGet(self, uid, pid):
            # Headers配置
            header = {
                "accept-encoding": "gzip, deflate, br",
                "accept-language": "zh-CN,zh;q=0.9",
                "cache-control": "max-age=0",
            }
            res = requests.get('https://blog.csdn.net/'+uid+'/article/details/'+pid, headers=header)
            status = res.status_code
            print(res.url)
            print(status)
            self.assertEqual(200, status)
    
    
    if __name__ == '__main__':
        unittest.main()
    
        @ddt.data({'key1': 'value1', 'key2': 'value2'},
                  {'key1': 'value3', 'key2': 'value4'})
        # @ddt.unpack
        def test_Get2(self, payload):
            # Headers配置
            header = {
                "accept-encoding": "gzip, deflate, br",
                "accept-language": "zh-CN,zh;q=0.9",
                "cache-control": "max-age=0",
             }
            r = requests.get("http://httpbin.org/get", headers=header,  params=payload)
            print(r.url)
            status = r.status_code
            print(status)
    
    

    Post 请求

        @ddt.data({'key1': 'value1', 'key2': 'value2'},
                  {'key1': 'value3', 'key2': 'value4'})
        def testPost(self, payload):
            header = {
                "accept-encoding": "gzip, deflate, br",
                "accept-language": "zh-CN,zh;q=0.9",
                "cache-control": "max-age=0",
             }
            url = 'http://httpbin.org/post'
            r = requests.post(url, headers=header, data=payload)
            print(r.text)
            status = r.status_code
            print(status)
            self.assertEqual(200, status)
    
  • 相关阅读:
    前端3 浮动布局,固定定位,绝对定位,相对定位
    前端2 字体|文本属性样式, 高级选择器
    前端1.概念
    前端,基础选择器,嵌套关系.display属性,盒模型
    数据库之索引
    数据库之进阶(视图,事务,存储过程)
    数据库,多表数据
    数据库之表的使用
    数据的演化(数据仓库的发展史)
    HDFS退出安全模式
  • 原文地址:https://www.cnblogs.com/lianstyle/p/11081127.html
Copyright © 2011-2022 走看看