Package: grappa-http
AboutHTTP request/response assertion plugin forgrappa.grappa-httpextendsgrappaassertion operators with HTTP protocol testing.To get started, take a look to thedocumentation,tutorialandexamples.Statusgrappa-httpis stillbeta qualitysoftware.Showcaseimportpookimportrequestsfromgrappa_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'}}})Full-featured error report example: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 bodyFeaturesFull-featured HTTP response assertions.Supports any protocol primitive assertions.First-class support for JSON body assertion.Built-in JSONSchema validation.Full-features request URL validation.Featured regular expression based assertion.Works withrequestsandaiohttpHTTP clients.Friendly and detailed assertion error reporting with body diff comparisons.Provides bothexpectandshouldassertion styles.Testing framework agnostic. Works withunittest,nosetests,pytest,behave…Works with Python 2.6+, 3+, PyPy and possibly other Python implementations.Supported HTTP clients✔requests✘aiohttp(work in progress)InstallationUsingpippackage manager:pipinstall--upgradegrappa-httpOr install the latest sources from Github:pipinstall-egit+git://github.com/grappa-py/http.git#egg=grappaHistoryv0.1.3 / 2017-04-26fix(adapters): use issubclass for adapter valid interface.v0.1.2 / 2017-04-25feat(api): add use_adapter() API for custom adapter registeringfeat(jsonschema): update example which uses satisfy attribute operatorv0.1.1 / 2017-03-29feat(requirements): upgrade grappa to latest versionfeat(operators): add output size limitfeat(docs): add thanks badgerefactor(docs): update descriptionfeat(examples): add featured examplefix(package): read version from grappa_http packagefix(docs): use grappa_http package0.1.0 (2017-03-25)First version (beta)