requests接口测试的一些请求构建和断言

更新时间:2023-06-04 07:27:12 阅读: 评论:0

requests接⼝测试的⼀些请求构建和断⾔
import requests
import unittest
import pystache医生职业介绍
室内体育课小游戏
from hamcrest import *
from jsonpath import jsonpath
议论class Test(unittest.TestCa):
def test_query(lf):
payload = {
"file": 3,
"name": "zcc",
}
respon = requests.post('/post',
json=payload)
print(respon.status_code)
# t)  # ⼆进制⽂本
行书字体图片# )  #  = t + ding
# print(respon.json())
def test_mustache(lf):
result = der('Hi {{person}}', {'person': 'zcc'})  # Hi zcc
asrt result == 'Hi zcc'
def test_json_path(lf):
respon = ('/categories.json')
# )
# print(jsonpath(respon.json(), '$..name'))
民主生活会主持词asrt jsonpath(respon.json(), '$..name')[0] == '开源项⽬'
asrt jsonpath(respon.json(), '$..name')[3] == '⽤户端测试'
def test_hamcrest(lf):
respon = ('/categories.json')
asrt_that(jsonpath(respon.json(), '$..name')[0], equal_to('开源项⽬'))
def test_json_schema(lf):
# todo: ⾃定义⽣成schema
pass
def test_cookies_by_headers(lf):上海梅雨季节
"""
传递cookie by headers
:return:
"""
header = {
"Cookie": 'number=2015130039',只有云知道
'Ur-Agent': 'python-requests/zcc'
}
respon = ('/cookies',
headers=header)
quest.headers)
def test_cookies_by_cookies(lf):
"""
传递cookie by cookies
:return:
"""
cookies = {
"number": '2015130039',
"name": 'zcc',
}
}
理性情绪疗法
respon = ('/cookies',
cookies=cookies)
quest.headers)
def test_auth(lf):
"""
使⽤auth认证此类请求
:return:
"""
from requests.auth import HTTPBasicAuth
respon = ('/basic-auth/balance/123',                                auth=HTTPBasicAuth("balance", "123"))
print(respon.status_code)
if __name__ == '__main__':
unittest.main()

本文发布于:2023-06-04 07:27:12,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/857415.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:请求   测试   职业   行书   生活
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图