Grappa的HTTP断言插件

grappa-http的Python项目详细描述


grappa logo

Build StatusPyPICoverage StatusDocumentation StatusStabilityCode ClimatePython VersionsSay Thanks

关于

用于grappa的http请求/响应断言插件。 grappa-http使用http协议测试扩展了grappa断言运算符。

要开始,请查看documentationtutorialexamples

状态

grappa-http仍然是beta质量软件。

展示

importpookimportrequestsfromgrappa_httpimportshould# Activate the HTTP mock enginepook.on()# Register a sample mockpook.get('server.org/foo?bar=baz',reply=200,response_headers={'Server':'nginx'},response_json={'foo':'bar'})# Perform HTTP requestres=requests.get('http://server.org/foo?bar=baz')# Test response status to be OKres|should.be.ok# Or alternatively using the status coderes|should.have.status(200)# Test request URLres|should.have.url.hostname('server.org')res|should.have.url.port(80)res|should.have.url.path('/foo')res|should.have.url.query.params({'bar':'baz'})# Test response body MIME content typeres|should.have.content('json')# Test response headers(res|(should.have.header('Content-Type').that.should.be.equal('application/json')))res|should.have.header('Server').that.should.contain('nginx')# Test response bodyres|should.have.body.equal.to('{\n    "foo": "bar"\n}')res|should.have.body.that.contains('foo')# Test response body lengthres|should.have.body.length.of(20)res|should.have.body.length.higher.than(10)# Test response JSON bodyres|should.have.json.equal.to({'foo':'bar'})res|should.have.json.have.key('foo')>should.be.equal.to('bar')# Validate response JSON bodies using JSONSchemares|should.implement.jsonschema({'$schema':'http://json-schema.org/draft-04/schema#','title':'Response JSON','type':'object','required':['foo'],'properties':{'foo':{'description':'foo always means foo','type':'string'}}})

全功能错误报告示例:

Traceback(mostrecentcalllast):File"grappa-http/tests/http_test.py",line38,intest_http_tutorialres|should.have.body.equal.to('{\n    "foo": "baa"\n}')File"grappa/grappa/test.py",line208,in__ror__returnself.__overload__(value)File"grappa/grappa/test.py",line196,in__overload__returnself.__call__(subject,overload=True)File"grappa/grappa/test.py",line73,in__call__returnself._trigger()ifoverloadelseTest(subject)File"grappa/grappa/test.py",line113,in_triggerraiseerrAssertionError:Oops!Somethingwentwrong!Thefollowingassertionwasnotsatisfiedsubject"{\n    "foo": "bar"\n}"shouldhavebodyequalto"{\n    "foo": "baa"\n}"Whatweexpectedaresponsebodydataequalto:{"foo":"baa"}Whatwegotinsteadaresponsebodywithdata:{"foo":"bar"}Differencecomparison>{>-"foo":"bar">?^>+"foo":"baa">?^>}WhereFile"grappa-http/tests/http_test.py",line38,intest_http_tutorial30|res|should.have.content('json')31|32|# Test response headers33|(res|(should.have.header('Content-Type')34|.that.should.be.equal('application/json')))35|res|should.have.header('Server').that.should.contain('nginx')36|37|# Test response body38|>res|should.have.body.equal.to('{\n    "foo": "baa"\n}')39|res|should.have.body.that.contains('foo')40|41|# Test response body length42|res|should.have.body.length.of(20)43|res|should.have.body.length.higher.than(10)44|45|# Test response JSON body

功能

  • 功能齐全的http响应断言。
  • 支持任何协议原语断言。
  • 对json主体断言的一级支持。
  • 内置jsonschema验证。
  • 完整功能请求URL验证。
  • 特色的基于正则表达式的断言。
  • requestsaiohttphttp客户端一起使用。
  • 友好和详细的断言错误报告与body diff比较。
  • 提供expectshould断言样式。
  • 测试框架不可知。使用unittestnosetestspytestbehave
  • 适用于Python2.6+、3+、PyPy和其他可能的Python实现。

支持的http客户端

安装

使用pippackage manager:

pip install --upgrade grappa-http

或者从github安装最新的源代码:

pip install -e git+git://github.com/grappa-py/http.git#egg=grappa

历史

V0.1.3/2017-04-26

  • fix(adapters): use issubclass for adapter valid interface.

V0.1.2/2017-04-25

  • feat(api): add use_adapter() API for custom adapter registering
  • feat(jsonschema): update example which uses satisfy attribute operator

V0.1.1/2017-03-29

  • feat(requirements): upgrade grappa to latest version
  • feat(operators): add output size limit
  • feat(docs): add thanks badge
  • refactor(docs): update description
  • feat(examples): add featured example
  • fix(package): read version from grappa_http package
  • fix(docs): use grappa_http package

0.1.0(2017-03-25)

  • 第一版(测试版)

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

推荐PyPI第三方库


热门话题
java在ArrayList中比较数字   java在Kotlin中使异步调用同步   让“Scala编程”junit示例在IntelliJ中工作的java问题   java Servlet侦听器未在ContextListener中设置属性   将Microsoft SQL Server数据库连接到我的Java项目   加载资源时出现java“需要注册工厂”异常   java如何使用POI检查excel中的重复记录?   java如何更改机器生成的代码   java如何确保重写的方法是同步的   用Spring编写Hibernate时的java XML奥秘   java管理mysql数据库中存储的用户权限   java如何运行。来自Javascript的jar方法   java我想在Web应用程序中进行身份验证&对桌面应用程序使用相同的凭据。我该怎么做?