用Python做测试——利用模块进行集中管理
2017-04-11 11:12
531 查看
新建account模块
#coding:utf-8
import requests
host = 'http://172.16.40.37:5000'
def test_username_exists(body):
url = host + '/cms/account/'
r = requests.get(url,
params=body)
# 希望成功的数据检查
if
body['expect'] ==
True:
if r.status_code ==
200 and
r.json()['yes'] ==
True:
print 'test sucess'
else:
print 'status_code=%s test_response=%s test_request=%s'
% (r.status_code, r.json(),body)
else:
if r.status_code ==
200 and
r.json()['yes'] ==
False:
print 'test sucess'
else:
print 'status_code=%s test_response=%s test_request=%s'
% (r.status_code, r.json(),body)
def data_test_test_username_exists(body):
for data in
body:
test_username_exists(data)
新建data模块
body = [{'username_exists':'文字','expect':True,'case_no':'case001','case_pourpse':'检查用户名存在的返回'},\
{'username_exists':'notqwen','expect':False,'case_no':'case002','case_pourpse':'检查用户名不存在的返回'},\
{'username_exists':'notqweddddddddddddddddddddddddddddddddn','expect':False,'case_no':'case003','case_pourpse':'非法参数值攻击校验,大于指定长度20'},\
{'username_exists':"""~!@#$%%^^&**(){}:"<>?<script>alert('</script>""",'expect':False,'case_no':'case004','case_pourpse':"""非法参数值攻击校验,特殊字符~!@#$%%^^&**(){}:"<>?<script>alert('</script>"""},\
]
新建dataRunAccount模块
import account
import data
if "__name__"
== "main":
# 测试username_exists的接口
account.data_test_test_username_exists(data.body)
#coding:utf-8
import requests
host = 'http://172.16.40.37:5000'
def test_username_exists(body):
url = host + '/cms/account/'
r = requests.get(url,
params=body)
# 希望成功的数据检查
if
body['expect'] ==
True:
if r.status_code ==
200 and
r.json()['yes'] ==
True:
print 'test sucess'
else:
print 'status_code=%s test_response=%s test_request=%s'
% (r.status_code, r.json(),body)
else:
if r.status_code ==
200 and
r.json()['yes'] ==
False:
print 'test sucess'
else:
print 'status_code=%s test_response=%s test_request=%s'
% (r.status_code, r.json(),body)
def data_test_test_username_exists(body):
for data in
body:
test_username_exists(data)
新建data模块
body = [{'username_exists':'文字','expect':True,'case_no':'case001','case_pourpse':'检查用户名存在的返回'},\
{'username_exists':'notqwen','expect':False,'case_no':'case002','case_pourpse':'检查用户名不存在的返回'},\
{'username_exists':'notqweddddddddddddddddddddddddddddddddn','expect':False,'case_no':'case003','case_pourpse':'非法参数值攻击校验,大于指定长度20'},\
{'username_exists':"""~!@#$%%^^&**(){}:"<>?<script>alert('</script>""",'expect':False,'case_no':'case004','case_pourpse':"""非法参数值攻击校验,特殊字符~!@#$%%^^&**(){}:"<>?<script>alert('</script>"""},\
]
新建dataRunAccount模块
import account
import data
if "__name__"
== "main":
# 测试username_exists的接口
account.data_test_test_username_exists(data.body)
相关文章推荐
- 利用python访问Hbase(Thrift模块安装与测试)
- 利用Python进行性能测试(上)
- 利用Python serial和openpyxl模块进行数据的读取和存储
- 利用Python进行Windows环境下的自动化测试
- python基础===利用unittest进行测试用例执行的几种方式
- python利用unittest进行测试用例执行的几种方式
- Python利用groupby模块进行Mysql分表数据的汇总统计
- 利用Python进行Windows环境下的自动化测试
- 【转】利用Python中的mock库对Python代码进行模拟测试
- 利用http模块进行post测试
- appium自动化测试实践之python利用unittest进行测试用例执行的几种方式(转载)
- caffe--python版利用训练好模型进行测试
- 利用Python中的mock库对Python代码进行模拟测试
- python利用requests库进行接口测试的方法详解
- 如何利用cURL和python对服务端和web端进行接口测试
- 利用python进行性能测试(下)
- Android SELinux 的认知以及 init 的相关知识,Linux 环境利用这2个模块进行白名单测试 -- 架构分析
- 利用python并发模块进行网站的状态检测
- python利用MySQLdb模块进行数据库的连接实现增查操作
- 利用NUnit和Watin进行web自动测试