Package: behave-restful
Behave Restful is a Behavior Driven Development (BDD) framework based onbehave, that implements a language suitable
to test and validate REST APIs and Services. It leverages the power of thegherkinlanguage to write
business readable tests that validate the behavior of REST APIs.Although, Behave Restful is implemented inpythonand
usesbehaveas underlying framework, it can
test services implemented in any language as easy as:Feature:API to add a new book to our collection
    As a user, I want to add a new book to my "to-read" collection.Scenario:Add a new book to collection.Givena request url http://my.reads/api/booksAnda request json payload"""{
                    "category": "reference",
                    "author": "Nigel Rees",
                    "title": "Sayings of the Century",
                    "price": 8.95,
                    "status": "to-read"
                }"""Whenthe request sends POSTThenthe response status is CREATEDAndthe response json matches"""{
                    "title": "BookObject",
                    "type": "object"
                    "properties": {
                        "id": {"type": "number"},
                        "category": {"type": "string"},
                        "author": {"type": "string"},
                        "title": {"type": "string"},
                        "price": {"type": "number"},
                        "status": {"type": "string", "enum": ["to-read", "reading", "read"]}
                    },
                    "required": ["id", "category", "title"]
                }"""Andthe response json at $.id is equal to100Andthe response json at $.category is equal to "reference"Andthe response json at $.title is equal to "Sayings of the Century"As you can see in the example, we send a POST request to the specified url with
a JSON payload, and we can validate the result very easy. First, we verify that
the status of the response is CREATED (it succeeds). Then we validate the
response JSON body using the expectedJSON Schema.
Finally, we validate specific values in the response usingJSONPathInstallationUse pip to install behave-restful in your projectpip install behave-restfulSetupTo add support forbehave-restfulsteps in your.featurefiles, you need to include behave-restful’s environment and step definitions.You can do this simply by adding two boilerplate files to your project:In the root of yourfeaturesdirectory, add thisenvironment.pyfile:# {your_project}/features/en/__init__.pyimportosimportbehave_restful.appasbr_appdefbefore_all(context):this_directory=os.path.abspath(os.path.dirname(__file__))br_app.BehaveRestfulApp().initialize_context(context,this_directory)context.hooks.invoke(br_app.BEFORE_ALL,context)defafter_all(context):context.hooks.invoke(br_app.AFTER_ALL,context)defbefore_feature(context,feature):context.hooks.invoke(br_app.BEFORE_FEATURE,context,feature)defafter_feature(context,feature):context.hooks.invoke(br_app.AFTER_FEATURE,context,feature)defbefore_scenario(context,scenario):context.hooks.invoke(br_app.BEFORE_SCENARIO,context,scenario)defafter_scenario(context,scenario):context.hooks.invoke(br_app.AFTER_SCENARIO,context,scenario)defbefore_step(context,step):context.hooks.invoke(br_app.BEFORE_STEP,context,step)defafter_step(context,step):context.hooks.invoke(br_app.AFTER_STEP,context,step)defbefore_tag(context,tag):context.hooks.invoke(br_app.BEFORE_TAG,context,tag)defafter_tag(context,tag):context.hooks.invoke(br_app.AFTER_TAG,context,tag)And underfeatures/stepsadd this__init__.pyfile:# {your_project}/features/steps/__init__.pyfrombehave_restful.langimport*