首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回数据的Tavern错误结构与预期不同-

返回数据的Tavern错误结构与预期不同-
EN

Stack Overflow用户
提问于 2022-02-11 18:56:13
回答 1查看 172关注 0票数 0

我在酒馆有个考试

代码语言:javascript
复制
test_name: Add products for tests

stages:
  - name: Add product one
    request:
      url: http://localhost:5566/product
      json:
        title: Product One
        description: Product One in our catalog
        picture: images/product.jpeg
        categories:
          - title: tshirt
          - title: casual
        price:
            currency: EUR
            units: 59
      method: POST
      headers:
        content-type: application/json
    response:
      status_code: 200
      headers:
        content-type: application/json
      save:
        json:
          product_id: uuid
    delay_after: 1

  - name: Get product one
    request:
      url: http://localhost:5566/product/{product_id}
      method: GET
      headers:
        content-type: application/json
    response:
      status_code: 200
      json:
        picture: images/product.jpeg
        title: Product One
      headers:
        content-type: application/json

第一阶段是将产品添加到数据库中的帖子,第二阶段是带有uuid的GET,uuid作为变量从第一阶段开始。

我想检查第二阶段的反应,只有两个具体的参数。产品的图片和标题

但是我得到了以下错误

代码语言:javascript
复制
ERROR    tavern.response.base:base.py:41 Structure of returned data was different than expected  - Extra keys in response: {'uuid', 'id', 'price_id', 'description'} (expected = '{'picture': 'images/product.jpeg', 'title': 'Product One'}' (type = <class 'dict'>), actual = '{'id': '1', 'uuid': '62c8c26d-c2c8-42a2-9111-2fd3186b08de', 'title': 'Product One', 'description': 'Product One in our catalog', 'picture': 'images/product.jpeg', 'price_id': '1'}' (type = <class 'dict'>))

可以只定义一组参数,还是必须使用整个JSON结构?

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-03 12:03:42

默认情况下,标头被设置为严格: False,而JSON重新设置为严格: True。

它们可以在全局范围内禁用,只需一个开关(--酒馆--严格的json: or :on),或者在test.yaml中。举例说明。

代码语言:javascript
复制
---
test_name: Check github API

stages:
  - name: Make sure the JSON contains location

    request:
      url: https://api.github.com/users/6wl
      method: GET

    response:
      strict: False
      status_code: 200
      json:
        location: Manchester

只有当JSON重新定位不等于曼彻斯特时,才会失败。

https://buildmedia.readthedocs.org/media/pdf/tavern/stable/tavern.pdf

第16页ish

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71085248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档