You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
having a request consisting of top-level object holding a list, how do I refer to such list element in response validation using "{tavern.request_vars}" ?
Output (with the syntax above, e.g. "{tavern.request_vars.json.requestBodyList[0].attribute}" ):
Errors:
E tavern._core.exceptions.MissingFormatError: tavern.request_vars.json.requestBodyList[0].attribute
------------------------------ Captured log call -------------------------------
ERROR tavern._core.dict_util:dict_util.py:41 Failed to resolve string '{tavern.request_vars.json.requestBodyList[0].attribute}'
ERROR tavern._core.dict_util:dict_util.py:44 Key(s) not found in format: tavern.request_vars.json.requestBodyList[0].attribute
Tested the other notation mentioned in docs, thing.nested.0, gives String.Formatter error, as mentioned in docs, this got most probably deprecated up from 1.0 version, e.g.
field_name = 'tavern.request_vars.json.requestBodyList.0.attribute', args = []
kwargs = <truncated>
def get_field(self, field_name, args, kwargs):
first, rest = _string.formatter_field_name_split(field_name)
obj = self.get_value(first, args, kwargs)
# loop through the rest of the field_name, doing
# getattr or getitem as needed
for is_attr, i in rest:
if is_attr:
> obj = getattr(obj, i)
E AttributeError: 'BoxList' object has no attribute '0'
I've added some more tests/examples in #938 for this, it should work - I'm guessing it's not your actual data but in the example you've posted it's probably because you're missing the complexListElement element and it should be:
I don't know if there is a way this could be made more obvious to the end user though, it should already print what format vars are available if you have debug logging turned on
sorry for the response delay in first place :)
In meanwhile I've refactored the code to call custom callable to flatten the response object, so I had to refactor it back to be able to confirm that what you've written works well too :)
Hello,
having a request consisting of top-level object holding a list, how do I refer to such list element in response validation using
"{tavern.request_vars}"
?tavern version: 2.11.0
example:
Output (with the syntax above, e.g. "{tavern.request_vars.json.requestBodyList[0].attribute}" ):
Tested the other notation mentioned in docs,
thing.nested.0
, gives String.Formatter error, as mentioned in docs, this got most probably deprecated up from 1.0 version, e.g.Didn't find an example for this in the docs, besides of https://tavern.readthedocs.io/en/latest/basics.html#response -> "thing.nested[0]" , however this applies to
save
keyword/section.Is there known way how to achieve list slicing while using
tavern.request_vars
in theresponse.json
section ?Thanks for any hint,
Regards,
Adrian
The text was updated successfully, but these errors were encountered: