taverntesting/tavern

Support for YAML Indexing and Advanced Assertions

Closed this issue · 1 comments

Description:
Consider a scenario where there is a list of items with quantities, and the goal is to assert the quantity of a specific item in a specific position without triggering a pass due to the presence of the same quantity in another position.

- test: Verify quantity for the third item
  stages:
    - response:
        status_code: 200
        json:
          items:
            - name: "Item1"
              quantity: 5
            - name: "Item2"
              quantity: 10
            - name: "Item3"
              quantity: 5

The provided example should only match the quantity of the third item and not inadvertently pass due to the presence of the same quantity elsewhere in the list.

I wish there was someplace I could add !index=2 or something as such
This is especially causing a blocker while trying to run negative tests

You can use jmespath assertions like

verify_response_with:
- function: tavern.helpers:validate_content
extra_kwargs:
comparisons:
- jmespath: pages
operator: "equals"
expected: 0
- jmespath: "data[?id=='bllp']"
operator: "equals"
expected: []
to do this but for specific situations like this it could also just be easier to write a specific external function to check this case.