我有这个dredd.yml配置文件:
paths:
"/network":
get:
produces:
- application/json;charset=utf-8
responses:
'200':
description: Ok
schema:
"$ref": "#/definitions/NetworkResponse"
"/network/{id}":
get:
produces:
- application/json;charset=utf-8
parameters:
- name: id
in: path
description: id
required: true
type: string
enum:
- "net-76faddf092e62151"
responses:
'200':
description: Ok
schema:
"$ref": "#/definitions/NetworkIdResponse"我想用python dredd钩子替换path中的{id}。我试过了:
import json
import dredd_hooks as hooks
response_stash = {}
@hooks.after("Networks > ALL ")
def save_network_id_to_stash(transaction):
# save HTTP response with IDs to the stash
response_stash[transaction['id']] = transaction['id']
print(transaction['id'])
@hooks.before("Networks > ID")
def add_network_id_to_request(transaction):
parsed_body = json.loads(response_stash['Networks > ALL'])
network_id = parsed_body['id']
transaction['fullPath'] = transaction['fullPath'].replace('net-76faddf092e62151', network_id)测试执行成功,但仅使用%1 id。第一个操作的答案将输出一个包含对象的列表,其中id在“id”中。如何替换path中的{id}并对所有网络进行测试?
发布于 2019-12-11 17:10:04
@hooks.before("Networks > ID > 200 > application/json;charset=utf-8)这是钩子名称的正确定义。
你可以在钩子函数中看到所有的变量transaction['real'],transaction['name']等等,其中一个变量就是print(transaction)。
https://stackoverflow.com/questions/59175732
复制相似问题