用Python做测试——利用模块进行集中管理

来源:互联网 发布:显卡满载测试软件 编辑:程序博客网 时间:2024/05/21 10:31

新建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)
    #   希望成功的数据检查
    
ifbody['expect'] ==True:
        if r.status_code ==200 andr.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 andr.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 inbody:
        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)

0 0
原创粉丝点击