如何在Tavern脚本中将数组和字典作为请求参数传递

时间:2019-03-25 11:52:50

标签: python dictionary scripting tavern

我正在编写一个Tavern脚本,必须以这种格式运行API调用:

https://example.com/httpapi?api_key=xyz_api_key&event=[{"user_id":"test1@gmail.com", 

"event_type":"buy_song", 

"user_properties":{"age": 23, "gender": "female","interests": "Music","sports": "Tennis"},

"event_properties":{"load_time": 0.8371, "source": "notification", "dates": ["monday", "tuesday"]},

"country":"US"}] 

这是我的小酒馆脚本:现在只需几个参数即可进行测试
注意:我也尝试过通过tavern脚本中的“ params”字段分别传递事件参数,但仍然会出错。

 test_name: Creating Users

 includes:
   - !include includes.yaml

   - name: Make sure we have the right ID

     # Define the request to be made...
     request:
       url: https://example.com/httpapi?api_key=c412eef2643e88ab67d764927e34ae0c&event={"user_id":"sk@gmail.com","event_type":"buy_song"} 

  method: POST

 response:
  status_code: 200

错误:

  E       MissingFormatError: ('"user_id"',)

0 个答案:

没有答案