为json api提供行为测试
behave-web-api的Python项目详细描述
为json api提供行为测试
安装
pip install behave-web-api
在features/steps/init中导入步骤.py
frombehave_web_api.stepsimport*
因此您可以使用功能文件中的步骤
Feature: Doing http requests Scenario: Send text body and headers Given I set header "X-My-Header" with value "Something" When I send a POST request to "/requests/echo" with body:""" Something """Then the response code should be 200And the response should contain json:""" { "headers": { "X-My-Header": "Something" }, "body": "%[A-Za-z]+%" } """Scenario: Send file using variables and environment variables Given I set the variable "DATA_DIR" with "$PWD/features/data"And I attach the file "$DATA_DIR/favicon.ico" as "upload"When I send a POST request to "/requests/echo"Then the response code should be 200And print response
并使用基URL环境变量运行:
BASE_URL=localhost:5000 behave features/requests.feature
可用步骤
- 我将变量“{}”设置为值“{}”
- 我将头“{}”设置为值“{}”
- 我将文件“{}”附加为“{}”
- 我用body向{}发送{}请求
- 我用值向“{}”发送{}请求
- 我向“{}”发送{}请求
- 响应代码应该是{}
- 响应应包含json
- 响应应包含文本
- 打印响应