从膨胀文件生成存根

swagger-stub的Python项目详细描述


Travis statusCode issuesJoin the chat at https://gitter.im/Trax-air/swagger-stubDependency Statushttps://img.shields.io/pypi/v/swagger-stub.svghttps://img.shields.io/pypi/dw/swagger-stub.svg

虚张声势存根

swagger存根自动创建swagger rest api的存根。这个存根可以在pytest fixture中的任何地方用于单元测试。

除了模拟api之外,还可以模拟一些调用,并检查对api的每个调用。

示例用法

importpytestimportrequestsfromswagger_stubimportswagger_stub# This is the fixture of your stub# You only need to specify the path of the swagger file and the address# where you want to bind your stub.@pytest.fixturedeftest_stub():returnswagger_stub([('swagger.yaml','http://foo.com')]).next()# Then you can use this fixture anywhere you want like your API is really running.deftest_swagger_stub(test_stub):# Get a definition exampletest_stub.definitions['Foo']# Check a simple callresponse=requests.get('http://foo.com/v1/bar/')assertresponse.status_code==200assertresponse.json()=={'foo':'bar'}# Check that an invalid body cause an errorresponse=requests.post('http://foo.com/v1/bar/',data='invalid data')assertresponse.status_code==400# Mock a calltest_stub.add_mock_call('get','/test',{'mock':'call'})response=requests.get('http://foo.com/v1/test')assertresponse.json()=={'mock':'call'}# Set some side_effect like in the mock librarytest_stub.add_mock_side_effect('get','/iter',[{'test':'1'},{'test':'2'},{'test':'3'}])response=requests.get('http://foo.com/v1/iter')assertresponse.json()=={'test':'1'}response=requests.get('http://foo.com/v1/iter')assertresponse.json()=={'test':'2'}response=requests.get('http://foo.com/v1/iter')assertresponse.json()=={'test':'3'}# This side effect will raise a custom errortest_stub.add_mock_side_effect('get','/error',Exception)withpytest.raises(Exception):response=requests.get('http://foo.com/v1/error')

文件

更多文档可在https://swagger-stub.readthedocs.org/en/latest/找到。

设置

进行安装pip install swagger存根

许可证

swagger存根是根据http://opensource.org/licenses/MIT授权的。

历史记录

0.2.1(2016-6-6)

  • 修复重复的基路径。

0.2.0(2016-5-2)

  • 添加对定义示例的访问权限。

0.1.1(2016-1-31)

  • 把执照改成麻省理工学院。

0.1(2016-1-29)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在ElasticSearch中插入条目的最佳方式是什么?   如何使用java播放视频并从中捕获帧   断言在Java良好实践中主动抛出断言错误?   swing Java编译有没有办法告诉编译器忽略部分代码?   java如何在执行另一个测试之后执行一个测试?   java添加两个数字链表   java如何通过代码编辑awt文本字段   jade无效缩进上的java错误;应为0个空格   java我可以在不安装facebook的情况下使用Android版facebook sdk。apk?   java现实地说,我为什么要使用DuckType或控制反转?   Java性能:Java逻辑从巨大的列表中找到最高的3个数字   java使用Lucene/Solr和Spring数据   java按照线程启动的顺序完成线程   java无法解析hibernate。cfg。脱机时使用xml