在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. 【SpringBoot源码分析】-Bean的加载过程

    -- 以下内容均基于2.1.8.RELEASE版本 在<SpringBoot启动过程的分析>系列文章中简要的对SpringBoot整体的启动流程作了梳理,但并未针对诸多细节进行分析.前面的 ...

  2. 浅谈synchronized和volatitle实现线程安全的策略

    什么是线程不安全 我对线程安全的理解就是多个线程同时操作一个共享变量时会产生意料之外的情况,这种情况就是线程不安全.注意:只有写操作才可能出现线程不安全,对共享变量只进行读操作线程是绝对安全的. 具体 ...

  3. Pandas的loc,iloc与ix的用法及区别

    1.先来谈一谈loc,loc这个方法就是你有啥我就用啥,你没有的我不用,pandas对象的index,columns有什么,pd.loc[index,column],index就是pd.index的其 ...

  4. Android Studio在android Emulator中运行的项目黑屏

    前言: 最近在做一个Android相关的小项目,因为之前这方面的项目做的比较的少.今天在使用虚拟机调试的时候经常出现一些莫名其妙的问题,经过自己多次的尝试和搜索终于解决了这些问题. 问题: 每次run ...

  5. ListBox控件简单的数据绑定

    <ListBox Margin="17,8,15,26" Name="ListBoxName" ItemsSource="{Binding Ta ...

  6. 技术分享|JavaScript的前世今生

    目录 一.什么是JavaScript 二.JavaScript的功能 三.JavaScript可以做什么 四.JavaScript框架 五.HTML,CSS和JavaScript 六.JavaScri ...

  7. Spring初识及其IOC入门

    一.框架 框架是一些类和接口的集合,它一个半成品,已经对基础的代码进行了封装并提供相应的API,开发者在使用框架时直接调用封装好的api可以省去很多代码编写,从而提高工作效率和开发速度. 二.Spri ...

  8. Linux下Apache服务的部署和配置

    目录 Apache服务的安装 yum源安装: 目录文件 源码包安装: 目录文件: Apache中添加对php的支持 Apache中添加php对mysql数据库的支持 Apache服务的高级配置 1:配 ...

  9. Python第四章-字典

    第四章 字典-当索引不好用时 4.0     字典可以理解成是C++里的map,可以映射任何类型.字典这种结构类型称为映射(mapping).   字典是Python中唯一内建的映射类型,字典中的值并 ...

  10. 发生系统错误 1275.此驱动程序被阻止加载 寒江孤钓<<windows 内核安全编程>> 学习笔记

    安装书中第一章成功安装first服务之后,在cmd窗口使用命令行 "net start first" 时, 出现 "发生系统错误 1275.此驱动程序被阻止加载" ...