i have a test in tavern
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
the first stage is a POST that add the Product to the database the second stage is a GET with the uuid that is coming, as variable, from the first stage.
I want to check the response of the second stage and only two specific parameters. the picture and the title of the product
but i get the following error
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'>))
is possible to define only a set of parameters or is mandatory to use the entire JSON structure?
thanks in advance
By default, headers are set to Strict: False, and JSON resp set to Strict: True.
They can be disabled globally, with a switch (--tavern-strict json:on headers:on), or in the test.yaml. Example.
---
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
Will only fail if location in the JSON resp does not equal Manchester.
https://buildmedia.readthedocs.org/media/pdf/tavern/stable/tavern.pdf
Page 16 ish