重载方法写delete请求
Posted lanyy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了重载方法写delete请求相关的知识,希望对你有一定的参考价值。
#encoding=utf-8
#__author__="Lanyangyang"
import unittest
import requests
import json
# This is a public delete method.
def test_public_delete(self, url, path, params):
# delete request method
response = requests.delete(url=url + path, params=params)
# Is the return status code 200?
self.assertEqual(response.status_code, 200, msg="状态码不是200")
# 判断返回文本
response_text = requests.delete(url=url + path, params=params).text
# 将响应内容转换成字典格式
response_dict = json.loads(response_text)
# 获取response message字段的值
response_message = response_dict[‘message‘]
# 判断message的值
self.assertEqual(response_message, ‘SUCCESS‘, msg=‘返回值不是SUCCESS‘)
print(response.text)
# 以json格式输出返回文本
response2 = requests.delete(url=url + path, params=params).json()
r = json.dumps(response2, indent=2, sort_keys=True)
print("返回信息如下:")
print(r)
print("test_public_delete调用成功")
#或者换种写法,先转换成文本,在取code和message,这样只需要请求一次
response_text = requests.delete(url=url + path, params=params).text
#将响应内容转换成字典格式
response_dict2=json.loads(response_text)
#获取字典中的code和message值
response_code2=response_dict2[‘code‘]
response_message2=response_dict2[‘message‘]
#断言判断
self.assertEqual(response_code2,200,msg="code不是200")
self.assertEqual(response_message2,‘SUCCESS‘,msg="msg不是SUCCESS")
以上是关于重载方法写delete请求的主要内容,如果未能解决你的问题,请参考以下文章