在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)的更多相关文章

  1. python单元测试unittest、setUp、tearDown()

    单元测试反应的是一种以测试为驱动的开发模式,最大的好处就是保证一个程序模块的行为符合我们设计的测试用例,在将来修改的时候,可以极大程度保证该模块行为仍然是正确的. 下面我编写一个Dict来,这个类的行 ...

  2. 新手必看:PyCharm安装教程,Python开发者的有力工具

    PyCharm是由JetBrains打造的一款Python IDE,VS2010的重构插件Resharper就是出自JetBrains之手. 同时支持Google App Engine,PyCharm ...

  3. pycharm环境下用Python+Django开发web搭建

    1.安装pycharm: 2.安装Python: 3.安装mysql: 4.安装Django; pip3 install django 5.创建Django工程命令方式: # 创建Django程序 d ...

  4. 【pycharm】在pycharm上,使用python的pip安装tensorflow过程

    如题:在pycharm上,使用python的pip安装tensorflow过程 最后成功安装的版本信息是: python版本是3.6.5 pip版本是9.0.1 pycharm版本是2018.1 te ...

  5. 如何利用pyCharm编写和运行python文件

    在安装python环境后,通常可以利用IDE pyCharm来编译我们的python文件.创建一个python文件夹,用pyCharm打开文件夹,在文件夹中新建一个python文件demo.py 也许 ...

  6. 安装好Pycharm后如何配置Python解释器简易教程

    呃呃,遇到坑了...... 安装完Python,没有去配置好Python解释器,直接打开Python项目包,去运行程序,程序输出结果只是显示 Process finished with exit co ...

  7. Unittest - Python 使用总结

    Unittest - Python 使用总结 批量执行 一.UnitTest TestSuite 控制用例执行的顺序 UnitTest 框架默认 main() 方法根据 ASCII 码的顺序加载测试用 ...

  8. python单元测试unittest

    单元测试作为任何语言的开发者都应该是必要的,因为时隔数月后再回来调试自己的复杂程序时,其实也是很崩溃的事情.虽然会很快熟悉内容,但是修改和 调试将是一件痛苦的事情,如果你在修改了代码后出现问题的话,而 ...

  9. [转]python单元测试unittest

    单元测试作为任何语言的开发者都应该是必要的,因为时隔数月后再回来调试自己的复杂程序时,其实也是很崩溃的事情.虽然会很快熟悉内容,但是修改和调试将是一件痛苦的事情,如果你在修改了代码后出现问题的话,而单 ...

随机推荐

  1. 牛客练习赛14B 区间的连续段

    题目链接 点我跳转 题目大意 给定一个长度为 \(N\) 的序列 \(A\) 和一个常数 \(K\) 有 \(M\) 次询问 每次询问查询一个区间 \([L , R]\) 内所有数最少分成多少个连续段 ...

  2. kuberadm集群升级

    升级kubernetes集群 注意不能跨版本升级 比如1.13.x 要先升级到1.14.x,不能直接升级到1.15.x 举例说明升级到1.15,和1.14有些参数不一样,具体看官网: https:// ...

  3. 模拟退火算法Python编程(3)整数规划问题

    1.整数规划问题 整数规划问题在工业.经济.国防.医疗等各行各业应用十分广泛,是指规划中的变量(全部或部分)限制为整数,属于离散优化问题(Discrete Optimization). 线性规划问题的 ...

  4. Python 使用oslo.vmware管理ESXI虚拟机

    oslo.vmware是OpenStack通用框架中的一部分,主要用于实现对虚拟机的管理任务,借助oslo.vmware模块我们可以管理Vmware ESXI集群环境. 读取所有节点主机 from o ...

  5. JAVA反序列化漏洞复现

    目录 Weblogic反序列化漏洞 Weblogic < 10.3.6 'wls-wsat' XMLDecoder 反序列化漏洞(CVE-2017-10271) Weblogic WLS Cor ...

  6. C#-几个STL相关

    C#结构体排序 1................................................. 声明 struct data { public string A; public ...

  7. Day001 基本的Dos命令

    基本的Dos命令 打开cmd的方式 开始+系统+命令提示符(有时候需要右键以管理员身份运行) Win+R键,输入cmd打开控制台 按住shift键的同时鼠标右键,点击在此处打开powershell窗口 ...

  8. 【转】Python调用C语言动态链接库

    转自:https://www.cnblogs.com/fariver/p/6573112.html 动态链接库在Windows中为.dll文件,在linux中为.so文件.以linux平台为例说明py ...

  9. 一文弄懂pytorch搭建网络流程+多分类评价指标

    讲在前面,本来想通过一个简单的多层感知机实验一下不同的优化方法的,结果写着写着就先研究起评价指标来了,之前也写过一篇:https://www.cnblogs.com/xiximayou/p/13700 ...

  10. [bug] docker: Error response from daemon: Conflict. The container name "/xx" is already in use

    改名.删除或重启容器 参考 https://www.cnblogs.com/youxin/p/12993816.html