PythonClassChy/python27Class/unitTest/class03242020/handle_request.py

41 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
=================================
Author: Flora Chen
Time: 2020/3/24 20:32
-_- -_- -_- -_- -_- -_- -_- -_-
=================================
"""
"""
封装的需求:
请求方法,请求地址,请求参数 excel中有这些数据
请求头:放到配置文件中
"""
import requests
def send(case):
"""
:param case: 字典格式的用例数据
:return:
"""
headers = ''
if case['method'] == 'get':
return requests.post(case['url'], params=eval(case['data']), headers=headers)
elif case['method'] == 'post':
return requests.post(case['url'], json=eval(case['data']), headers=headers)
elif case['method'] == 'put':
return requests.put(case['url'], json=eval(case['data']), headers=headers)
"""
这个封装方法还不完善,只是提供了一种封装思路。
其实没有必要做封装。可以直接用requests模块中的request
"""
response = requests.request('get', url='http://www.baidu.com')
response1 = requests.request('post', url='http://www.baidu.com', json='', headers='')
print(response.text)