Skip to main content

About

A basic library could decrease the workload.Most of the problem solved in a real testing job.

Function info

interface test

parameter template url = "https://test/api/log?requestID=testid&clientToken=testtoken" body ={"date": "2018-11-04 10:10:10", "actions": [{"actionTime": 1542248466944,"note"]}}

interface basic verification


verification of the value of parameter is null

verification of the parameter in a GET method restful interface link, such as requestID:

url = "https://test/api/log?requestID=&clientToken=testtoken"

verification of request body in a POST restful interface, type of the body, such as form or raw will self adapted. e.g

body ={"date": "", "actions": [{"actionTime": 1542248466944,"note"]}}

body ={"date": "2018-11-04 10:10:10", "actions": [{"actionTime": "","note"]}}

the value of parameter is ""

verification of null parameter

verification of the parameter in a GET method restful interface link, such as requestID:

url = "https://test/api/log?clientToken=testtoken"

verification of request body in a POST restful interface, type of the body, such as form or raw will self adapted. e.g

body ={ "actions": [{"actionTime": 1542248466944,"note"]}}

body ={"date": "2018-11-04 10:10:10", "actions": [{"note"]}}

verification of length of parameter

range of the length is 1 to 100000。


performance test of interface coming soon UI automatic test

how to install

pip install BlueTest

or

https://pypi.org/project/BlueTest/

Usage and examples

example

└─Project
        test1.py

test1.py:

import BlueTest
BlueTest.test()

└─Project
│  test1.py
├─log
│      all.log #log
│      error.log #error log
├─result #reuslt
│      data.txt
└─srcdata
    │  test.csv  #postman serialize
    │  test.json.postman_collection #postman example
    └─api #generated .py file according postman
            log.py

Usage

import BlueTest
#This will produce the csv file for test case
BlueTest.initPostMan("test") 

#默认postamen文件路径
# default post man path is .//srcdata//name.json.collection
#default csv file path is.//srcdata//test.csv
BlueTest.testByCsvData("test") # this will produce the result

BlueTest.initPostMan("test") #this will produce the csv file
BlueTest.initPostMan("test",result_path=path) #specify the csv file path
BlueTest.testByCsvData("test") 
#this will produce the result 
BlueTest.testByCsvData("test",normal_test=True) #basic interface verification
BlueTest.testByCsvData("test",normal_test=Fasle) #not verify the result
BlueTest.testByCsvData("test",mkpy=True) 

import requests
url = "https://nbrecsys.4paradigm.com/action/api/log"
querystring = {'requestID': 'Abac6ban', 'clientToken': '1f9d3d10b0ab404e86c2e61a935d3888'}
payload = {"date":"2018-11-04 10:21:06","actions":[{"requestID":"2222","actionTime":1542248466944,"action":"show","sceneId":420,"userId":"xubyCjC6zO","itemId":"user_define","itemSetId":"39","uuid_tt_dd":"10_28867322960-222-222","specialType":"csdn_net_alliance_ads","ads":1}]}
headers ={'Origin': ' https://blog.csdn.net',
	 'User-Agent': ' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
	 'Content-Type': ' text/plain',
	 'Accept': ' */*',
	 'Referer': ' https://blog.csdn.net/qq_37159430/article/details/79970518',
	 'Accept-Encoding': ' gzip, deflate, br',
	 'Accept-Language': ' zh-CN,zh;q=0.8'}
response = requests.request("POST", url, params=querystring,data=payload,)
print(response.text)

The other function refer to :gun:

简介

:waxing_gibbous_moon:几个本质懒到家,却被工作压迫的人。为了降低自己的工作量,拍脑袋决定编写一个让小白也可以使用的测试库。一切的出发点都是几个懒人在实际工作中遇到的问题和场景。做这一切的目的是为了少做事。:waning_gibbous_moon:

功能介绍

接口测试

参数模板 下文的介绍中会使用该模板进行说明 url = "https://test/api/log?requestID=testid&clientToken=testtoken" body ={"date": "2018-11-04 10:10:10", "actions": [{"actionTime": 1542248466944,"note"]}}


接口基础校验


参数值判空校验

链接中的参数校验,即一般情况下GET参数的校验,以requestID为例:

url = "https://test/api/log?requestID=&clientToken=testtoken"

请求主体参数的校验,即一般情况下POST参数的校验,form,raw等参数类型均自动处理。 以body中的date为例,请求参数如下:

body ={"date": "", "actions": [{"actionTime": 1542248466944,"note"]}}

以body中的actions[0][actionTime]为例,请求参数如下:

body ={"date": "2018-11-04 10:10:10", "actions": [{"actionTime": "","note"]}}

空值以空字符串为标准。


参数判空校验

链接中的参数校验,即一般情况下GET参数的校验,以requestID为例:

url = "https://test/api/log?clientToken=testtoken"

请求主体参数的校验,即一般情况下POST参数的校验,form,raw等参数类型均自动处理。 以body中的date为例,请求参数如下:

body ={ "actions": [{"actionTime": 1542248466944,"note"]}}

以body中的actions[0][actionTime]为例,请求参数如下:

body ={"date": "2018-11-04 10:10:10", "actions": [{"note"]}}

参数长度校验

参数长度校验范围为1-100000。


额外参数校验

增加非接口文档约定参数进行校验。但是只在数据层级发生变化时进行校验。插入数据的键值均等于"test" 范例数据只会进行以下几种情况的校验:

url = "https://test/api/log?requestID=testid&clientToken=testtoken&test=test" body ={"date": "2018-11-04 10:10:10", "actions": [{"actionTime": 1542248466944}}

url = "https://test/api/log?requestID=testid&clientToken=testtoken" body ={"date": "2018-11-04 10:10:10","test":"test", "actions": [{"actionTime": 1542248466944]}}

url = "https://test/api/log?requestID=testid&clientToken=testtoken" body ={"date": "2018-11-04 10:10:10", "actions": [{"actionTime": 1542248466944,"test":"test"]}}


接口性能测试 待添加 UI自动化 功能已实现,说明待添加

安装说明

安装命令pip install BlueTest

or

https://pypi.org/project/BlueTest/

使用说明及范例

范例

└─Project
        test1.py

test1.py:

import BlueTest
BlueTest.test()

└─Project
│  test1.py
├─log
│      all.log #日志
│      error.log #错误日志
├─result #结果
│      data.txt
└─srcdata
    │  test.csv  #postman文件的序列化
    │  test.json.postman_collection #范例的postman文件
    └─api #根据postman生成的相关接口py文件
            log.py

使用说明

import BlueTest
BlueTest.initPostMan("test") #执行完成会生成相应csv文件
#默认postamen文件路径.//srcdata//name.json.collection
#默认csv文件生成路径.//srcdata//test.csv
BlueTest.testByCsvData("test") #执行完成会生成相应结果
#结果包括 日志文件log 结果文件resul

BlueTest.initPostMan("test") #执行完成会生成相应csv文件
BlueTest.initPostMan("test",result_path=path) #指定csv文件生成路径
BlueTest.testByCsvData("test") #执行完成会生成相应结果
BlueTest.testByCsvData("test",normal_test=True) #进行接口基础验证
BlueTest.testByCsvData("test",normal_test=Fasle) #不进行接口基础验证
BlueTest.testByCsvData("test",limit_check=True,extras_check=True) #limit_check 进行参数长度校验 extras_check进行额外参数校验 输出结果如下

exceptionCheck: ['requestID']为空 urlparams:True response:(True, '{"statuses":[{"ActionLogStatusCode":0}]}') exceptionCheck: ['requestID']不传 urlparams:True response:(True, '{"statuses":[{"ActionLogStatusCode":0}]}') extrasCheck: ['requestID'] 额外参数校验 response:(False, '{"code":3401,"info":"上传日志的时间错误","data":null}')

BlueTest.testByCsvData("test",mkpy=True) #生成接口py文件范例如下
BlueTest.testByCsvData("test",mkpy=True) #生成接口py文件范例如下
BlueTest.testByCsvData("test",mkpy=True) #生成接口py文件范例如下

import requests
url = "https://nbrecsys.4paradigm.com/action/api/log"
querystring = {'requestID': 'Abac6ban', 'clientToken': '1f9d3d10b0ab404e86c2e61a935d3888'}
payload = {"date":"2018-11-04 10:21:06","actions":[{"requestID":"2222","actionTime":1542248466944,"action":"show","sceneId":420,"userId":"xubyCjC6zO","itemId":"user_define","itemSetId":"39","uuid_tt_dd":"10_28867322960-222-222","specialType":"csdn_net_alliance_ads","ads":1}]}
headers ={'Origin': ' https://blog.csdn.net',
	 'User-Agent': ' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
	 'Content-Type': ' text/plain',
	 'Accept': ' */*',
	 'Referer': ' https://blog.csdn.net/qq_37159430/article/details/79970518',
	 'Accept-Encoding': ' gzip, deflate, br',
	 'Accept-Language': ' zh-CN,zh;q=0.8'}
response = requests.request("POST", url, params=querystring,data=payload,)
print(response.text)

其他功能详见源码 :gun:

Metadata

Release files for BlueTest 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BlueTest 0.2.3
File Size Uploaded
BlueTest-0.2.3.tar.gz 15.9 kB Details

Release files / BlueTest-0.2.3.tar.gz

Download URL BlueTest-0.2.3.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e5197657f14ae95ea727cccb00bbca56cef8a3800bce4c6485876cb6303afd64
BLAKE2b-256 checksum
How to use checksums
ef48f1fc90d4aeba6a2a43d625c7859e9ac663aba3978fc39f937c8ff7f68c96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

1 release file

0.3.0

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

This release

0.2.3 This release

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page