您的位置:首页 > 编程语言 > Python开发

用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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: