在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. 通过Fiddler 远程 对 安卓手机 iPhone 苹果手机 访问请求抓包 Android IOS14.4 fiddler代理 无法联网

    Fiddler 中的设置 1 查看 Fiddler所在 电脑的内网 ip地址. (cmd  > ipconfig 查看本机ipv4地址) 2 Fiddler 设置 允许远程设备连接: Fiddl ...

  2. linux 查看cpu型号、memory

    查看CPU信息(型号) [root@TX-220-60-211 supdev]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c 40 In ...

  3. 一台window服务器部署多个tomcat(超简单配置)!!!

    1.首先准备好已经安装好的jdk环境,点击查看JDK安装. 2.准备好一个全新的tomcat,我这里使用的是tomcat-7.0.109.rar绿色版. 3.解压文件,并复制成三份.我这里是放在F:\ ...

  4. 基于MATLAB的手写公式识别(2)

    基于MATLAB的手写公式识别 图像的预处理(除去噪声.得到后续定位分割所需的信息.) 预处理其本质就是去除不需要的噪声信息,得到后续定位分割所需要的图像信息.图像信息在采集的过程中由于天气环境的影响 ...

  5. Spring Security 上

    Spring Security 上 Security-dome 1.创建项目 创建一个Spring Boot项目,不用加入什么依赖 2.导入依赖 <dependencies> <!- ...

  6. hdu4771 水搜索(状态压缩+bfs)

    题意:      给你一个n*m的地图,问你从起点出发,吧所有的宝藏都捡完用的最少时间. 思路:k <= 4,水题,直接开一个数组mark[now][x][y];now代表的是当前检宝藏的二进制 ...

  7. Android进程的so注入--Poison(稳定注入版)

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/53869796 Android进程的so注入已经是老技术了,网上能用的Android ...

  8. Python第三章-字符串

    第三章  字符串 3.1 基本字符串操作 Python的字符串和元组差不多,是不可以进行改变的,如果想改变值,可以尝试list序列化之后在进行修改. {    website = 'http://ww ...

  9. axios提交表单

    后端使用@RequestBody接收jsons数据 因为后端接收json数据,所以前端也要发送json 项目的前端是使用layui的数据表单 案例方法 方法一:JSON字符串 提交的数据格式 {&qu ...

  10. 【maven】Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site)

    问题描述 site一点击就报错,如下 Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (defau ...