请求参数data没有key,只有value值,不支持
aminacheng opened this issue · 1 comments
aminacheng commented
对于有些用例,请求body直接是data:‘xxx’格式,并没有key值
- test:
name: notify_msg
variables:
- data_di: '{"tokenid": "$token", "time": "${get_msg_notify_time()}", "physical_id": "$physical_id", "type": "11", "channel": "0", "is_main": "1"}'
request:
url: xxxx/message/msgnotify
method: POST
data: ${encode_multipart_formdata($data_di)}
extract:
- result: content.result
validate:
- "eq": [$result, 'ok']
在平台中,request,选择data,不填key值,只填写一个value值,结果,保存后,data字典就是空的
INFO:HttpRunnerManager:notify_msg用例更新成功: {'test': {'request': {'url': 'xxxx/message/msgnotify', 'method': 'POST', 'data': {}}, 'name': 'notify_msg', 'validate': [{'comparator': 'equals', 'check': '$result', 'expected': 'ok'}], 'extract': [{'result': 'content.result'}], 'variables': [{'data_di': '{"tokenid": "$token", "time": "${get_msg_notify_time()}", "physical_id": "$physical_id", "type": "11", "channel": "0", "is_main": "1"}'}]}}
我要的效果是‘data’:{'${encode_multipart_formdata($data_di)}'}
有办法吗
briangt commented
确实不支持,需要自己改造下,具体在common的case_info_logic中
改造后代码:
if request_data and data_type:
if data_type == 'json':
test.get('request').setdefault(data_type, request_data)
else:
keyvalue=request_data.get('test')
if len(keyvalue)==1 and keyvalue[0]['key'] == '':
test.get('request').setdefault(data_type, keyvalue[0]['value'])
data_dict = key_value_dict('data', **request_data)
if not isinstance(data_dict, dict):
return data_dict
test.get('request').setdefault(data_type, data_dict)
只要key置空且data总数为1即可生成非kv形式的data,同时temlates也需要进行一些修改