https://github.com/sohoffice/tavalidate
Utilities to help you validate Tavern response
https://github.com/sohoffice/tavalidate
rest-api unittest xml
Last synced: 3 months ago
JSON representation
Utilities to help you validate Tavern response
- Host: GitHub
- URL: https://github.com/sohoffice/tavalidate
- Owner: sohoffice
- Created: 2020-02-09T10:36:27.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T15:26:18.000Z (over 6 years ago)
- Last Synced: 2025-12-16T06:56:02.464Z (7 months ago)
- Topics: rest-api, unittest, xml
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
tavalidate, utilities to help you validate [Tavern](https://tavern.readthedocs.io/en/latest/) response.
Installation
------------
Tavalidate can be installed through pip.
```
pip install tavalidate
```
XML Validate
----
Tavern has great built-in Json support, but things are difficult when it comes to XML.
Use tavalidate.xmlv package to validate XML response.
XML validation example:
```
response:
status_code: 200
verify_response_with:
function: tavalidate:assert_xml
extra_kwargs:
expected: |
!anyint
```
Simply put, pass the expected xml as an argument to the `tavalidate.xmlv.validate` function. The
function will validate the xml structure, node value and attribute value.
### extra_kwargs
Below are the supported extra kwargs of `tavalidate.xmlv.validate` function.
#### expected
This is the expected XML string.
You may use some (not all) of the tavern magic values to match data of your specified type:
- !anything: This matches value of any type.
- !anystr: Matches any string
- !anyint: Matches any integer
- !anyfloat: Matches any float
- !anybool: Matches any boolean
#### strict
Use `strict: True` if you want to make sure there's no extra tag in the response.
XML Save
----
Use tavalidate.xmlv package to save XML response.
It allows you to use [XPath](https://en.wikipedia.org/wiki/XPath) to specify the value to save
inside the xml document. If the XPath somehow selects multiple nodes, tavalidate will print a
warning, but the first value will still be saved.
XML save example:
```
response:
save:
$ext:
function: tavalidate:save_xml
extra_kwargs:
variables:
bar: '/foo/bar/text()'
at1: '/foo/@at1'
```
Logging
-------
Configure the logger `tavalidate` so you can see the response body and other logs in
DEBUG level.