dredd api测试框架的python钩子桥
dredd_hooks的Python项目详细描述
关于
此包包含Dredd API Testing Framework之间的桥 和python环境以简化测试挂钩的实现 由Dredd提供。用python编写Dredd钩子,将API Blueprint与python项目粘合在一起
用法示例:
importdredd_hooksashooks@hooks.before_alldeffoo(transactions):fortintransactions:t['request']['headers']['content-type']='application/json'
下载
你可以在PyPI看到所有的available versions。
来源(tar.gz或checkout)
打开存档文件,输入dredd-hooks-python目录并运行:
python setup.py install
用法
- 在hooks.py: 中创建挂钩文件
importdredd_hooksashooks@hooks.before("Machines > Machines collection > Get Machines")defbefore_hook(transaction):transaction['skip']="true"
用dredd运行它:
$ dredd apiary.apib localhost:3000 --language python --hookfiles ./hooks.py
API
模块dredd_hooks定义以下修饰符before,after, before_all,after_all,before_each,after_each, before_validation,before_each_validation。before, before_validation和after挂钩由transaction name标识。
你可以把那些装饰工组合在一起。所以可以使用一个函数 对于不同的钩子,但是要注意一些钩子有一个列表 事务作为参数而不是单个事务。
importdredd_hooksashooks@hooks.after_all@hooks.before_all@hooks.before_each@hooks.after_each@hooks.before_validation('Machines > Machines collection > Get Machines')@hooks.before("Machines > Machines collection > Get Machines")@hooks.after("Machines > Machines collection > Get Machines")defmulti_hook_function(trans):ifisinstance(trans,list):print('called with list of transactions')else:iftrans['name']=='Machines > Machines collection > Get Machines':trans['skip']='true'
贡献
- 叉开它
- 创建功能分支(git checkout -bmy-newfeature)
- 提交更改(git commit -am 'Add some feature')
- 推动(git push origin my-new-feature)
- 创建新的拉取请求
测试
不要忘记测试,请参见test目录。项目使用 unittest包和tox。
对于带有Dredd接口的集成测试,项目使用基于ruby的 aruba所以要让它运行make 确保已安装Ruby,然后执行以下操作:
$ bundle install
设置完成后,您可以使用以下命令轻松运行测试:
$ bundle exec cucumber
有关集成测试的更多详细信息,请参见 dredd-hooks-template repo
copyright: | Copyright (c) 2015 Apiary Czech Republic, s.r.o. |
---|---|
license: | MIT, see LICENSE for details. |