在pycharm进行单元测试(unittest python)
在Edit Configuration中添加Python test 选中相应的脚本或者文件夹
# coding:utf-8
import unittest
import requests
from config import BASE_URL
from config import SC_OK, SC_INTERNAL_SERVER_ERROR DEBUG = True # 镜像
class Iamge(object):
def __init__(self):
self.ct_user_id = "b4186147a58a2188e9e2e21c99"
self.os_id = "a477c664559311e79de10242ac110002"
self.disk_size = 30
self.uuid = "af6276a7-1984-4e88-8630-5f4e384b95c2"
self.data_center = 1
self.os_type = "1"
self.login_name = "admin"
self.name = "win2008-20170512"
self.os_name = "win2008"
self.share = 1 # 镜像查询列表
def images_list(self):
URL_ = BASE_URL + "/api/images/list/"
payload = {"ct_user_id": self.ct_user_id, "os_id": self.os_id}
operation_return = requests.get(URL_, params=payload, headers=dict(Referer=URL_))
print "*********** return status is " + str(operation_return.status_code)
print "*********** return type is " + str(operation_return.headers['content-type'])
print "*********** content is \n" + str(operation_return.content)
return operation_return # 查询某个镜像
def query_images(self):
URL_ = BASE_URL + "/api/images/query/"
payload = {"ct_user_id": self.ct_user_id, "os_id": self.os_id, "share": self.share, "name": self.name}
operation_return = requests.get(URL_, params=payload, headers=dict(Referer=URL_))
print "*********** return status is " + str(operation_return.status_code)
print "*********** return type is " + str(operation_return.headers['content-type'])
print "*********** content is \n" + str(operation_return.content)
return operation_return # 创建镜像
def create_images(self):
URL_ = BASE_URL + "/api/images/create/"
payload = {"ct_user_id": self.ct_user_id, "os_id": self.os_id, "disk_size": self.disk_size, "uuid": self.uuid,
"data_center": self.data_center, "os_type": self.os_type, "login_name": self.login_name,
"name": self.name, "os_name": self.os_name}
operation_return = requests.post(URL_, data=payload, headers=dict(Referer=URL_))
print "*********** return status is " + str(operation_return.status_code)
print "*********** return type is " + str(operation_return.headers['content-type'])
print "*********** content is \n" + str(operation_return.content)
return operation_return # 更新镜像
def update_images(self):
URL_ = BASE_URL + "/api/images/update/"
payload = {"ct_user_id": self.ct_user_id, "os_id": self.os_id, "id": 5, "name": self.name}
operation_return = requests.post(URL_, data=payload, headers=dict(Referer=URL_))
print "*********** return status is " + str(operation_return.status_code)
print "*********** return type is " + str(operation_return.headers['content-type'])
print "*********** content is \n" + str(operation_return.content)
return operation_return # 删除镜像
def delete_images(self):
URL_ = BASE_URL + "/api/images/delete/"
payload = {"ct_user_id": self.ct_user_id, "os_id": self.os_id, "id": 5}
operation_return = requests.post(URL_, data=payload, headers=dict(Referer=URL_))
print "*********** return status is " + str(operation_return.status_code)
print "*********** return type is " + str(operation_return.headers['content-type'])
print "*********** content is \n" + str(operation_return.content)
return operation_return image = Iamge() class TestCaseImage(unittest.TestCase):
def setUp(self):
pass def tearDown(self):
pass # 获取镜像列表
if DEBUG:
def testImageList(self):
images_list_status_code = image.images_list().status_code
self.assertEqual(images_list_status_code, SC_OK) # 获取某个镜像
if DEBUG:
def testImageQuery(self):
query_images_status_code = image.query_images().status_code
self.assertEqual(query_images_status_code, SC_OK) # 创建镜像
if DEBUG:
def testImageCreate(self):
create_images_status_code = image.create_images().status_code
self.assertEqual(create_images_status_code, SC_OK) # 更新镜像
if DEBUG:
def testImageUpdate(self):
update_images_status_code = image.update_images().status_code
self.assertEqual(update_images_status_code, SC_OK)
# 删除镜像
if DEBUG:
def testImageDelete(self):
delete_images_status_code = image.delete_images().status_code
self.assertEqual(delete_images_status_code, SC_OK) if __name__ == "__main__":
unittest.main() # run all tests
在pycharm进行单元测试(unittest python)的更多相关文章
- python单元测试unittest、setUp、tearDown()
单元测试反应的是一种以测试为驱动的开发模式,最大的好处就是保证一个程序模块的行为符合我们设计的测试用例,在将来修改的时候,可以极大程度保证该模块行为仍然是正确的. 下面我编写一个Dict来,这个类的行 ...
- 新手必看:PyCharm安装教程,Python开发者的有力工具
PyCharm是由JetBrains打造的一款Python IDE,VS2010的重构插件Resharper就是出自JetBrains之手. 同时支持Google App Engine,PyCharm ...
- pycharm环境下用Python+Django开发web搭建
1.安装pycharm: 2.安装Python: 3.安装mysql: 4.安装Django; pip3 install django 5.创建Django工程命令方式: # 创建Django程序 d ...
- 【pycharm】在pycharm上,使用python的pip安装tensorflow过程
如题:在pycharm上,使用python的pip安装tensorflow过程 最后成功安装的版本信息是: python版本是3.6.5 pip版本是9.0.1 pycharm版本是2018.1 te ...
- 如何利用pyCharm编写和运行python文件
在安装python环境后,通常可以利用IDE pyCharm来编译我们的python文件.创建一个python文件夹,用pyCharm打开文件夹,在文件夹中新建一个python文件demo.py 也许 ...
- 安装好Pycharm后如何配置Python解释器简易教程
呃呃,遇到坑了...... 安装完Python,没有去配置好Python解释器,直接打开Python项目包,去运行程序,程序输出结果只是显示 Process finished with exit co ...
- Unittest - Python 使用总结
Unittest - Python 使用总结 批量执行 一.UnitTest TestSuite 控制用例执行的顺序 UnitTest 框架默认 main() 方法根据 ASCII 码的顺序加载测试用 ...
- python单元测试unittest
单元测试作为任何语言的开发者都应该是必要的,因为时隔数月后再回来调试自己的复杂程序时,其实也是很崩溃的事情.虽然会很快熟悉内容,但是修改和 调试将是一件痛苦的事情,如果你在修改了代码后出现问题的话,而 ...
- [转]python单元测试unittest
单元测试作为任何语言的开发者都应该是必要的,因为时隔数月后再回来调试自己的复杂程序时,其实也是很崩溃的事情.虽然会很快熟悉内容,但是修改和调试将是一件痛苦的事情,如果你在修改了代码后出现问题的话,而单 ...
随机推荐
- User-Agent大全 python
1 # -*-coding:utf-8 -*- 2 3 import random 4 5 # 返回一个随机的请求头 headers 6 def getheaders(): 7 # 各种PC端 8 u ...
- HUAWEI AppGallery Connect翻译服务升级,方便应用出海本地化
HUAWEI AppGallery Connect翻译服务全新升级,携手新宇智慧.语言桥等多家服务商为全球开发者提供优质的翻译服务,解决应用在全球分发时面临的多语言本地化问题,通过平台化与全环节的翻译 ...
- Mybatis3源码笔记(六)SqlSession执行过程
前几篇大致分析了初始化的过程,今天打算走一个SqlSession具体执行过程. @Test void shouldSelectAllAuthors() { try (SqlSession sessio ...
- Mybatis3源码笔记(一)环境搭建
1. 源码下载 地址:https://github.com/mybatis/mybatis-3.git. 国内访问有时确实有点慢,像我就直接先fork.然后从git上同步到国内的gitte上,然后在i ...
- 日志功能 - 使用 conf 配置文件
配置文件:Logger.conf 工具类:LogUtil.py 测试类:testDemo.py 执行效果 配置文件:Logger.conf 定义日志的类型.级别.格式等信息. [loggers] # ...
- SpringMVC请求参数解析
请求参数解析 客户端请求在handlerMapping中找到对应handler后,将会继续执行DispatchServlet的doPatch()方法. 首先是找到handler对应的适配器. Hand ...
- Windows之磁盘管理
0x01 磁盘管理概述 磁盘管理是一项计算机使用时的常规任务,它是以一组磁盘管理应用程序的形式提供给用户的,他们位于计算机管理控制台中,它包括查错程序和磁盘碎片整理程序以及磁盘整理程序.(来源百度 ...
- C/C++ 手工实现IAT导入表注入劫持
DLL注入有多种方式,今天介绍的这一种注入方式是通过修改导入表,增加一项导入DLL以及导入函数,我们知道当程序在被运行起来之前,其导入表中的导入DLL与导入函数会被递归读取加载到目标空间中,我们向导入 ...
- 开启Android应用调试选项的工具XDebug的介绍
本文博客地址:https://blog.csdn.net/QQ1084283172/article/details/81187769 最近这段时间比较郁闷,就不分享和学习比较复杂的Android逆向技 ...
- IPC$共享和其他共享(C$、D$)
目录 net use共享命令的用法 IPC$ IPC空连接 ipc$使用的端口 关闭IPC$共享 net use共享命令的用法 net use #查看连接 net share ...