为json api提供行为测试

behave-web-api的Python项目详细描述


Build Status

为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
  • 响应应包含文本
  • 打印响应

致谢

其余步骤基于behat webapiextension[1]

[1]https://github.com/Behat/WebApiExtension

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Clojure关键字在内存中的大小是多少?   Java中有固定长度的通用数组对象吗?   PostgreSQL:通过Java更新我的用户表   错误:使用java解析xml   java Json显示列表中对象的名称   java比较JodaTime时区   与JAVA中的API和包的区别?   java的int值在for循环中不改变   谷歌应用引擎中的java RSA   迁移到spring 5后出现java非法字符错误   java Websphere管理控制台不工作   JavaGSON如何始终在json中包含毫秒?   带有空格和双引号的windows Java ProcessBuilder命令参数失败   java错误:重复的zip条目[43.jar:org/apache/http/annotation/NotThreadSafe.class]