zoukankan      html  css  js  c++  java
  • 重载方法写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")



  • 相关阅读:
    性能测试相关名词
    Java中的并发工具类:CountDownLatch、CyclicBarrier和Semaphore
    spring与mybatis五种整合方法
    Powerdesigner使用技巧
    基于Redis的Spring cache 缓存介绍
    AspectJ AOP介绍
    Spring AOP的实现原理
    -webkit-tap-highlight-color
    Zero Clipboard js+swf实现的复制功能使用方法
    CSS3 RGBA 属性高级用法
  • 原文地址:https://www.cnblogs.com/lanyy/p/10420505.html
Copyright © 2011-2022 走看看