• 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)
    
  • 相关阅读:
    Mybatis详解(二)
    Mybatis详解(一)
    Java集合
    Java基础之IO
    Java异常知识点!
    HTTP状态码
    ajax传字符串时出现乱码问题的解决
    Json 文件 : 出现 Expected value at 1:0 问题的解决
    java @XmlTransient与@Transient区别
    文件的上传和回显
  • 原文地址:https://www.cnblogs.com/lianstyle/p/11081127.html
Copyright © 2020-2023  润新知