Python Hooks Bridge for Dredd API Testing Framework
This package contains a bridge between Dredd API Testing Framework and Python environment to ease implementation of testing hooks provided by Dredd. Write Dredd hooks in Python to glue together API Blueprint with your Python project
import dredd_hooks as hooks @hooks.before_all def foo(transactions): for t in transactions: t['request']['headers']['content-type'] = 'application/json'
From source (tar.gz or checkout)
Unpack the archive, enter the dredd-hooks-python directory and run:
python setup.py install
- Create a hook file in hooks.py:
import dredd_hooks as hooks @hooks.before("Machines > Machines collection > Get Machines") def before_hook(transaction): transaction['skip'] = "true"
Run it with Dredd:
$ dredd apiary.apib localhost:3000 --language python --hookfiles ./hooks.py
Module dredd_hooks defines following decorators before, after, before_all, after_all, before_each, after_each, before_validation, before_each_validation. before, before_validation and after hooks are identified by transaction name.
Usage is very similar to sync JS hooks API
- Fork it
- Create your feature branch (git checkout -b my-newfeature)
- Commit your changes (git commit -am 'Add some feature')
- Push (git push origin my-new-feature)
- Create a new Pull Request
Don’t forget about tests, see test directory. The project uses unittest package and tox.
$ bundle install
After the setup you can run the test easily with:
$ bundle exec cucumber
More details about the integration test can be found in the dredd-hooks-template repo
|copyright:||Copyright (c) 2015 Apiary Czech Republic, s.r.o.|
|license:||MIT, see LICENSE for details.|