Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for YAML Indexing and Advanced Assertions #895

Open
varsharyalii opened this issue Nov 24, 2023 · 1 comment
Open

Support for YAML Indexing and Advanced Assertions #895

varsharyalii opened this issue Nov 24, 2023 · 1 comment

Comments

@varsharyalii
Copy link

varsharyalii commented Nov 24, 2023

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

@michaelboulton
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants