引入unittest框架

get请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#coding: utf-8
import unittest
import requests
import json
class TestGet(unittest.TestCase):
 
    def setUp(self):
        self.test_url = 'http://localhost:8080/jenkins/api/json?tree=jobs[name]'
 
 
    def test_get(self):
        self.r = requests.get(self.test_url)
        '''
        result = self.r.text
        json_result = json.loads(result) #反序列化过程
        '''
        json_result = self.r.json()  #反序列化等同于上面注释代码
        print json_result
        self.assertEquals(json_result['jobs'][0]['name'],'check_python_version')
 
if __name__ == "__mian__":
    unittest.mian()

post请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#coding: utf-8
import unittest
import requests
import json
 
class TestPost(unittest.TestCase):
 
    def setUp(self):
        self.test_url = 'http://localhost:8080/jenkins/job/check_python_version/build'
 
    def test_post(self):
        self.r = requests.post(self.test_url, data={}, auth=('admin''123456'))
        print self.r.status_code
        self.assertEqual(self.r.status_code, 200)
if __name__ == "__mian__":
    unittest.mian()

python接口测试的更多相关文章

  1. Python接口测试实战1(上)- 接口测试理论

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  2. Python接口测试实战4(下) - 框架完善:用例基类,用例标签,重新运行上次失败用例

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  3. Python接口测试实战5(上) - Git及Jenkins持续集成

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  4. Python接口测试实战5(下) - RESTful、Web Service及Mock Server

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  5. Python接口测试实战4(上) - 接口测试框架实战

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  6. Python接口测试实战3(下)- unittest测试框架

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  7. Python接口测试实战3(上)- Python操作数据库

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  8. Python接口测试实战2 - 使用Python发送请求

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  9. Python接口测试实战1(下)- 接口测试工具的使用

    如有任何学习问题,可以添加作者微信:lockingfree 课程目录 Python接口测试实战1(上)- 接口测试理论 Python接口测试实战1(下)- 接口测试工具的使用 Python接口测试实战 ...

  10. python接口测试(post,get)-传参(data和json之间的区别)

    python接口测试如何正确传参: POST 传data:data是python字典格式:传参data=json.dumps(data)是字符串类型传参 #!/usr/bin/env python3 ...

随机推荐

  1. MySQL 5.7 GTID OOM bug案例分析 --大量压测后主从不同步

    转载自:http://www.sohu.com/a/231766385_487483 MySQL 5.7是十年内最为经典的版本,这个观点区区已经表示过很多次.然而,经典也是由不断地迭代所打造的传奇.5 ...

  2. shiro认证-SSM

    shiro认证-SSM pom <dependency> <groupId>org.apache.shiro</groupId> <artifactId> ...

  3. 【概率论】4-2:期望的性质(Properties of Expectation)

    title: [概率论]4-2:期望的性质(Properties of Expectation) categories: - Mathematic - Probability keywords: - ...

  4. Java主线程在子线程执行完毕后再执行

    一.join() Thread中的join()方法就是同步,它使得线程之间由并行执行变为串行执行. public class MyJoinTest { public static void main( ...

  5. Java并发指南11:解读 Java 阻塞队列 BlockingQueue

    解读 Java 并发队列 BlockingQueue 转自:https://javadoop.com/post/java-concurrent-queue 最近得空,想写篇文章好好说说 java 线程 ...

  6. matplotlib画图报错This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.

    之前用以下代码将实验结果用matplotlib show出来 plt.plot(np.arange(len(aver_reward_list)), aver_reward_list) plt.ylab ...

  7. 多进程之间的互斥信号量的实现(Linux和windows跨平台)

    最近工作中遇到了一些关于文件读取权限的问题.当一个程序中对一个固定名称的文件做了读写的操作的时候,外界通过并发式的调用这个应用的时候,可能存在多个进程同时去操作这个文件,这个时候可能会造成调用失败的问 ...

  8. 配置nginx支持path_info

    默认情况下,nginx是不支持path_info的,我们需要做些配置让它支持. location ~ \.php(.*)$ { root /var/www/nginx/html; fastcgi_pa ...

  9. Mapper抽象类参数

    Mapper< Object, Text, Text, IntWritable> Mapper< Text, Text, Text, Text> Mapper< Text ...

  10. 顺序容器删除元素 vector list deque

    #include <iostream>#include <list>#include <algorithm>#include <string> usin ...