cdent / gabbi

Declarative HTTP Testing for Python and anything else
http://gabbi.readthedocs.org/
Other
148 stars 34 forks source link

jsonhandler: read data from disk improvements #250

Closed trevormccasland closed 6 years ago

trevormccasland commented 6 years ago

UPDATE: dropping the yaml loading from this issue and updating the querying of the subset of data from disk to enable JSONPath support like the left hand side does already for the jsonhandler. For example, $.versions[?status = "current"].version: <@endpoint.json:[?status = "current"].version

reading data from disk can be done today with the jsonhandler by using the '<@myfile.json' we would like to improve this to work on larger files by allowing a user to specify a subset. Also being able to read from a yaml source would be nice.

  1. allow yaml to be loaded from disk this should be easy since json is supposed to be a subset of it.

    • a foreseen problem I see with this is the test loader grabs all *.yaml files, we can get around this without modifying the test loader by naming our test yaml files with a .yml extension
  2. Allow a user to specify a subset to load. It appears to be a simple change. I think we can use the ‘:’ character (or whatever we agree on) to split on the accessors for the dictionary and apply those to the self.loads(info) call like so https://github.com/trevormccasland/gabbi/commit/5a17517bb52fe6d4206cee42e63bca9d73ee8f35 ( I forgot to swap out the json.loads with yaml, ignore the point in the commit message :/ )

    • Our problem is the management of the json files, we would prefer that we could load our site deployment information in a yaml format and use those values for some of our api responses without having to create a json file for every test.

The following is a simple example, the contents of the files for our use case will be much larger and contains information that is related to how our apis are deployed and do not necessarily correlate to a single api response.

Example: endpoint.json contents: '[{"status": "current", "version": 1.0}]'

response_json_paths: $.versions[0][‘status’]: <@endpoint.json:[0][status]

cdent commented 6 years ago

@FND and I talked about this at length in IRC. We're still debating some of the details of the syntax and think yaml handling is something that could be put off either to later or a ContentHandler.

Don't be put off by the tone FND and I take with one another and apparent inability to be brief, that's just part of how we have something akin to fun.

trevormccasland commented 6 years ago

I agree, I will put off the yaml handling for later. I discussed this with my team today and we would like to use the same JSONPath syntax the left hand side uses so that we can use regex like the following.

$.versions[?status = "current"].version: <@endpoint.json:[?status = "current"].version