Skip to main content

A toolchain for testing REST APIs in BDD manner.

Project description

# bddrest

Toolchain to define and verify REST API in BDD.

[![Build Status](http://img.shields.io/pypi/v/bddrest.svg)](https://pypi.python.org/pypi/bddrest)

## Branches

### master

[![Build Status](https://travis-ci.org/Carrene/bddrest.svg?branch=master)](https://travis-ci.org/Carrene/bddrest)
[![Coverage Status](https://coveralls.io/repos/github/Carrene/bddrest/badge.svg?branch=master)](https://coveralls.io/github/Carrene/bddrest?branch=master)

### develop

[![Build Status](https://travis-ci.org/Carrene/bddrest.svg?branch=develop)](https://travis-ci.org/Carrene/bddrest)
[![Coverage Status](https://coveralls.io/repos/github/Carrene/bddrest/badge.svg?branch=develop)](https://coveralls.io/github/Carrene/bddrest?branch=develop)


## Quick start


```python

import sys
import json

from bddrest.authoring import given, when, then, and_, response, composer


def wsgi_application(environ, start_response):
path = environ['PATH_INFO']
if path.endswith('/None'):
start_response('404 Not Found', [('Content-Type', 'text/plain;charset=utf-8')])
return ''
start_response('200 OK', [('Content-Type', 'application/json;charset=utf-8')])
result = json.dumps(dict(
foo='bar'
))
yield result.encode()


with given(
wsgi_application,
title='Quickstart!',
url='/books/id: 1',
as_='visitor'):

then(response.status == '200 OK')
and_('foo' in response.json)
and_(response.json['foo'] == 'bar')

when(
'Trying invalid book id',
url_parameters={'id': None}
)

then(response.status_code == 404)

composer.dump(sys.stdout)

```

Will produce:

```yaml

base_call:
as_: visitor
response:
headers:
- 'Content-Type: application/json;charset=utf-8'
json:
foo: bar
status: 200 OK
title: Quickstart!
url: /books/:id
url_parameters:
id: '1'
verb: GET
calls:
- response:
headers:
- 'Content-Type: text/plain;charset=utf-8'
status: 404 Not Found
title: Trying invalid book id
url_parameters:
id: None

```

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bddrest-0.5.4b0.tar.gz (9.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page