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

response_json_paths not equals #263

Open
m-barthelemy opened this issue Dec 2, 2018 · 1 comment
Open

response_json_paths not equals #263

m-barthelemy opened this issue Dec 2, 2018 · 1 comment

Comments

@m-barthelemy
Copy link

Is is currently possible to ensure that a field in the response is not equal to a value?

I know I can do

response_json_paths:
          $.name: hello

to check for equality, but is there a way I can ensure the opposite ($.name is not equal, or different from, hello?)

@cdent
Copy link
Owner

cdent commented Dec 2, 2018

Initially I thought you were after something like #227 but I see that you want the field to be present but have a a different value. I assume you don't know the new value, just that it is different from hello.

Probably the best way to do this is with a negative assertion in a regex:

  response_json_paths:
      $.name: /^(?!hello)/

That will need some tweaking if you're expecting the new data to be a substring that might include hello.

Other ideas that might be worth exploring, below:

Depending on the structure of your data you might be able to use len (see https://gabbi.readthedocs.io/en/latest/jsonpath.html ) to filter a list and checks its length.

Another option is to mark a test xfail, so that if it succeeds that's a failure:

tests:                                                                         
- name: check for value                                                        
  xfail: True                                                                  
  POST: /                                                                      
  verbose: all                                                                 
  request_headers:                                                             
      content-type: application/json                                           
  data:                                                                        
      items:                                                                   
          - name: cow                                                          
            sound: moo                                                         
  response_json_paths:                                                         
      $.items[?name = "horse"].sound: not here

That, however, requires a test running that treats unexpected success as a failure (not all do).

Let me know which of these work, or if none of them do. If you're happy please close the issue.

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