【发布时间】:2020-06-24 23:11:05
【问题描述】:
我正在使用 Tavern 测试我的 REST 端点。基本上,我所做的只是做一个 GET 请求,尝试保存响应,然后使用该响应的一部分进行后续的 UPDATE 测试。
# test_.tavern.yaml file
# GET
test_name: Get Rules by ServiceCode
stages:
- name: Get Rules by a ServiceCode
request:
method: GET
url: http://localhost:9000/record/v1/admin/rules
params:
service_code: "ZEL302" #hardcoded
response:
status_code: 200
save:
$ext:
function: rule:save_rule_no # saving the results into a variable called "saved_rule_no"
---
# UPDATE
test_name: Update Rule
stages:
- name: Update a Rule
request:
method: PUT
url: "http://localhost:9000/record/v1/admin/rules/69"
json:
ruleNo: !int "{saved_rule_no}" # use the saved variable here
category: "tavernc"
identifier: "taverni"
operator: "taverno"
value: "tavernv"
productId: "tavernpid"
serviceCode: "tavernsc"
templateNo: 1 #hardcoded
response:
status_code: 200
# rule.py file
def save_rule_no(response):
"""
After creating a Rule, get the Rule's ruleNo field to use for testing update/delete
"""
ruleNo = response.json()[0]["ruleNo"]
return Box({"saved_rule_no": ruleNo})
我收到下面的错误,说变量无法识别。此方法适用于 Tavern 0.34.0,但不适用于 1.0.0。对于 1.0.0,您将如何做到这一点?
scenario/test_.tavern.yaml::Insert Rules PASSED [ 25%]
scenario/test_.tavern.yaml::Get Rules by ProductId PASSED [ 50%]
scenario/test_.tavern.yaml::Get Rules by ServiceCode PASSED [ 75%]
scenario/test_.tavern.yaml::Update Rule FAILED [100%]
========================================================================= FAILURES =========================================================================
Format variables:
saved_rule_no = '???'
【问题讨论】:
标签: python api rest testing tavern