在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. 浅入Kubernetes(8):外网访问集群

    目录 查询 Service Service 外部服务类型 配置 ServiceType 伸缩数量 阶段总结 在前面几篇文章中,我们学习了 kubeadm .kubectl 的一些命令,也学会了 Dep ...

  2. 所谓 ICMP,不过将军与士卒而已

    什么是 ICMP 协议 关于这点我们在 IP 协议那篇文章中提过一嘴,IP 协议作为一种提供不可靠数据交付的网络层协议,在传输的过程中,其 IP 数据报可能会发生丢失.重复.延迟和乱序等各种情况, 但 ...

  3. 今日浅谈循环 for与while

    昨天写的条件分支结构与今日写的循环是编程两个最基本的也非常重要的个结构 for循环 for循环可以从一个元组(tuple),列表(list),字典(dict),集合(set),字符串(string') ...

  4. 逻辑引擎、工作流、CMDB小感

    工作流是啥? 在界面上画画点点就能生成代码,这是很吸引人的事情,也是很多自动化工具追求的目标.工作流就是这么一个东西,通过定义流程和输入,就能实现你想要的东西,不需要编写代码. 工作流的实现 通过解析 ...

  5. 03- 手机App功能测试要点以及登录页面的测试

    当你进入一个互联网公司以后,首先对公司结构有所了解,然后遇到问题找对应的工作人员,效率就事半功倍了. 公司的结构: 产品经理 项目经理 设计师 开发人员 测试人员 运维人员 运营人员 配置管理 App ...

  6. php 操作 redis 常用命令

    原文地址: https://www.cnblogs.com/zhanghanwen16/p/9510481.html 1.redis连接与认证 //连接参数:ip.端口.连接超时时间,连接成功返回tr ...

  7. CString,string,char数组的转换

    来源:http://ticktick.blog.51cto.com/823160/317550 //----------------ANSI字符串转换为UNICODE字符串-------------- ...

  8. <JVM上篇:内存与垃圾回收篇>01-JVM与Java体系结构

    笔记来源:尚硅谷JVM全套教程,百万播放,全网巅峰(宋红康详解java虚拟机) 同步更新:https://gitee.com/vectorx/NOTE_JVM https://codechina.cs ...

  9. 【python】Leetcode每日一题-颠倒二进制位

    [python]Leetcode每日一题-颠倒二进制位 [题目描述] 颠倒给定的 32 位无符号整数的二进制位. 示例1: 输入: 00000010100101000001111010011100 输 ...

  10. [PowerShell] 快速入门, 基本语法, 常用类型, 函数, .NET 互操作

    PowerShell 快速入门 开始之前, 我们认定你已经有一定的编程基础, 熟悉 .NET 中的类型与对象. 此文章对于 .NET 开发者来说更简单哦! 在 PowerShell 中, 几乎一切都是 ...