Package: bddrest
bddrestToolchain to define and verify REST API in BDD.Table of ContentsQuick startWriting testsDumping a StoryAuto DumpingMarkdownCommand Line InterfaceEnabling the bash autocompletion for bddrestQuick startWriting testsUsingGiven,when, functions as you see in the example below, you can
determine and assert the behaviour of yourREST API.Thestory,response,statusobjects are some proxies for currently
writing story(inside the with Given( ... ): context) and it's response.
and the last response after aGivenand orwhen.importreimportsysimportjsonfrombddrest.authoringimportGiven,when,response,statusdefwsgi_application(environ,start_response):path=environ['PATH_INFO']ifpath.endswith('/None'):start_response('404 Not Found',[('Content-Type','text/plain;charset=utf-8')])yieldb''else:start_response('200 OK',[('Content-Type','application/json;charset=utf-8')])result=json.dumps(dict(foo='bar'))yieldresult.encode()withGiven(wsgi_application,title='Quickstart!',url='/books/id: 1',as_='visitor')asstory:assertstatus==200assertstatus=='200 OK'assert'foo'inresponse.jsonassertresponse.json['foo']=='bar'when('Trying invalid book id',url_parameters={'id':None})assertresponse.status==404Dumping aStorystory.dumps()Produces:base_call:as_:visitordescription:As a member I have to POST a book to the library.form:name:BDD Bookquery:a:bresponse:headers:-'Content-Type:application/json;charset=utf-8'json:foo:barstatus:200 OKtitle:Posting a bookurl:/books/:idurl_parameters:id:'1'verb:GETcalls:-response:headers:-'Content-Type:text/plain;charset=utf-8'status:404 Not Foundtitle:Trying invalid book idurl_parameters:id:NoneYou may load the story again from this yaml withStory.loads(yaml).There are two additional methods available to dump and load to
and from a file:story.load(file)andstory.dump(file)Auto DumpingYou may pass theautodumpargument of theGivenfunction to configure the
auto-dumping::param autodump: A file-like object to write dumped story.
                 Default is `None`, means autodump is disabled by default.Auto DocumentationYou may pass theautodocargument of theGivenfunction to configure the
auto-documentation::param autodoc: A file-like object to write documentation.
                Default is `None`, meana autodoc is disabled by default.
:param autodoc_format: Either ``markdown`` or ``html``. default is
                       ``markdown``.MarkdownYou can usestory.document([formatter_factory=MarkdownFormatter])to generate documentation
in arbitrary format for example:Markdown.There is also a CLI to do this:bddrestdocument<story.yml>story.md## Posting a book

### GET /books/:id

As a member I have to POST a book to the library.

### Url Parameters

Name | Example
--- | ---
id | 1

### Query Strings

Name | Example
--- | ---
a | b

### Form

Name | Example
--- | ---
name | BDD Book

### Response: 200 OK

#### Headers

* Content-Type: application/json;charset=utf-8

#### Body

```json
{"foo": "bar"}
```

## WHEN: Trying invalid book id

### Url Parameters

Name | Example
--- | ---
id | None

### Response: 404 Not Found

#### Headers

* Content-Type: text/plain;charset=utf-8Command Line InterfaceAfter installing the project a command namedbddrestwill be available.bddrest-hEnabling the bash autocompletion for bddrestAdd this into your.bashrcand or$VIRTUAL_ENV/bin/postactivate.eval"$(register-python-argcompletebddrest)"Mockup serverWhen you want serve the server for special yaml file using like below.bddrestmockupserveryamlfilename