HTTP assertion plugin for grappa
Project description
About
HTTP request/response assertion plugin for grappa.
To get started, take a look to the documentation, tutorial and examples.
Status
grappa-http is still beta quality software.
Showcase
import pook
import requests
from grappa_http import should
# Activate the HTTP mock engine
pook.on()
# Register a sample mock
pook.get('server.org/foo?bar=baz', reply=200,
response_headers={'Server': 'nginx'},
response_json={'foo': 'bar'})
# Perform HTTP request
res = requests.get('http://server.org/foo?bar=baz')
# Test response status to be OK
res | should.be.ok
# Or alternatively using the status code
res | should.have.status(200)
# Test request URL
res | 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 type
res | 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 body
res | should.have.body.equal.to('{\n "foo": "bar"\n}')
res | should.have.body.that.contains('foo')
# Test response body length
res | should.have.body.length.of(20)
res | should.have.body.length.higher.than(10)
# Test response JSON body
res | should.have.json.equal.to({'foo': 'bar'})
res | should.have.json.have.key('foo') > should.be.equal.to('bar')
# Validate response JSON bodies using JSONSchema
res | should.have.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'
}
}
})
Features
Full-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 with requests and aiohttp HTTP clients.
Friendly and detailed assertion error reporting with body diff comparisons.
Provides both expect and should assertion styles.
Testing framework agnostic. Works with unittest, nosetests, pytest, behave…
Works with Python 2.6+, 3+, PyPy and possibly other Python implementations.
Supported HTTP clients
Installation
Using pip package manager:
pip install --upgrade grappa-http
Or install the latest sources from Github:
pip install -e git+git://github.com/grappa-py/http.git#egg=grappa
History
0.1.0 (2017-03-25)
First version (beta)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for grappa_http-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd6d53d08f4314e6df28ebf2d367c8107897209792d0583b64797e582de7fddc |
|
MD5 | 0a2115c2a92ac8b1f954b5849abec53e |
|
BLAKE2b-256 | 2ae4f5152c9290d3e0ff65c52db3d3cded32cb67ef60d41c8c1ac41260a759d8 |