为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第三方库


热门话题
添加到Linkedlist后int与Integer的java比较不起作用   服务器启动时来自tomcat的java通知回调   在java中如何将float转换为double?   使用Java数据Bean连接到Siebel时出错   我如何反对像Java这样的强类型语言中的Ducktyping呢?   运行vert的json。x与java安全管理器   java大O表示法解释嵌套while循环   配置My gradle java项目找不到log4j2。json   验证我需要编写一个包含特殊字符和0到9的数字的java字符串来验证密码   java Univocity解析器:从这里调用函数无效:parserSettings。选择字段(*some_function*);   java在MVC上应用TDD   运行时的java按钮开关   Java8:如何流式处理int数组、提取低位字节和创建字节数组   linux无法在从Java启动的子进程中为SIGQUIT设置信号处理程序   Gradle具有真正混合的java和scala源代码