I am testing my REST endpoints with Tavern. Basically, all I am doing is doing a GET request, trying to save the response, and then use a part of that response for a subsequent UPDATE test.
# 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})
I get the error below saying the variable is not recognized. This approach works on Tavern 0.34.0 but not for 1.0.0. How would you do this for 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 = '???'
Aucun commentaire:
Enregistrer un commentaire