python - 如何绑定(bind)请求的输出以便在pyresttest 中的后续测试中使用?

标签 python rest functional-testing

我正在使用 pyresttest 来测试我的 API 端点。我想将一个测试的输出绑定(bind)到一个可在后续测试中使用的变量。我需要这个来测试像 /object/{id} 这样的端点,其中 ID 是 MongoDB 生成的哈希值。该哈希值是随机的,并且每次数据库播种时都会发生变化。我看不到有任何方法可以在不播种数据库、搜索特定条目、绑定(bind)该条目的 ID,然后使用它来测试端点的情况下测试此端点。

最佳答案

保存一个测试的输出是通过 extract_binds 元素实现的。 pyresttest/examples/miniapp-extract-validate.yaml 中的 pyrestest 存储库中有一个使用示例:

- config:
    - testset: "Demonstrate use of extract after creating a person"
- test: # create entity by POST
    - name: "Create person"
    - url: "/api/person/"
    - method: "POST"
    - body: '{"first_name": "Test","last_name": "User","login": "testuser"}'
    - headers: {Content-Type: application/json}
    - expected_status: [201]
    - extract_binds:
        - 'id': {'jsonpath_mini': 'id'}
- test:
    - name: "Get person you just created and validate them"
    - url: {'template': "/api/person/$id/"}
    - validators:
        - compare: {jsonpath_mini: 'id', comparator: 'str_eq', expected: {template: '$id'}}
        - extract_test: {jsonpath_mini: 'login', test: 'exists'}

关于python - 如何绑定(bind)请求的输出以便在pyresttest 中的后续测试中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34901764/

相关文章:

ruby-on-rails - 使用 RESTful 身份验证插件的 Ruby on Rails 功能测试

python - 请求 URL 中缺少方案

python - 使用 Python、C++ 和 pybind11 返回和传递原始 POD 指针(数组)

python - 如何将生成器对象转换为列表?

java - 如何在文本中反射(reflect)传入的 GET 请求?

java - 自动化 Java Web 应用程序的冒烟、功能和回归测试?

python - 子集 pandas 数据帧以根据另一个数据帧中的值获取特定行数

api - 在 Grails 中使用 Enunciate

web-services - 休息给我的妻子 - 有人可以解释这个短语吗?

c# - ServiceStack AppHostHttpListenerBase 无法连接到远程服务器