behave-restful


Namebehave-restful JSON
Version 0.4.4 PyPI version JSON
download
home_pagehttps://github.com/behave-restful/behave-restful
SummaryImplements Gherking language for REST services.
upload_time2023-01-13 18:32:24
maintainer
docs_urlNone
authorIsaac Rodriguez
requires_python
licenseMIT
keywords rest bdd behave gherkin test automation testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
Behave Restful
==============


.. image:: https://travis-ci.org/behave-restful/behave-restful.svg?branch=master
   :target: https://travis-ci.org/behave-restful/behave-restful
   :alt: Build Status


Behave Restful is a Behavior Driven Development (BDD) framework based on 
`behave <https://pythonhosted.org/behave/>`_\ , that implements a language suitable 
to test and validate REST APIs and Services. It leverages the power of the 
`gherkin <https://github.com/cucumber/cucumber/wiki/Gherkin>`_ language to write 
business readable tests that validate the behavior of REST APIs.

Although, Behave Restful is implemented in `python <http://www.python.org>`_ and 
uses `behave <https://pythonhosted.org/behave/>`_ as underlying framework, it can 
test services implemented in any language as easy as:

.. code-block:: gherkin


   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.
           Given a request url http://my.reads/api/books
               And a request json payload
                   """
                   {
                       "category": "reference",
                       "author": "Nigel Rees",
                       "title": "Sayings of the Century",
                       "price": 8.95,
                       "status": "to-read"
                   }
                   """
           When the request sends POST
           Then the response status is CREATED
               And the 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"]
                   }
                   """
               And the response json at $.id is equal to 100
               And the response json at $.category is equal to "reference"
               And the 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 expected `JSON Schema <http://json-schema.org/>`_. 
Finally, we validate specific values in the response using 
`JSONPath <http://goessner.net/articles/JsonPath/>`_

Installation
------------

Use pip to install behave-restful in your project

.. code-block::

   pip install behave-restful

Setup
-----

To add support for ``behave-restful`` steps in your ``.feature`` files, 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 your ``features`` directory, add this ``environment.py`` file:

.. code-block:: python

   # {your_project}/features/en/__init__.py

   import os

   import behave_restful.app as br_app


   def before_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)


   def after_all(context):
       context.hooks.invoke(br_app.AFTER_ALL, context)


   def before_feature(context, feature):
       context.hooks.invoke(br_app.BEFORE_FEATURE, context, feature)


   def after_feature(context, feature):
       context.hooks.invoke(br_app.AFTER_FEATURE, context, feature)


   def before_scenario(context, scenario):
       context.hooks.invoke(br_app.BEFORE_SCENARIO, context, scenario)


   def after_scenario(context, scenario):
       context.hooks.invoke(br_app.AFTER_SCENARIO, context, scenario)


   def before_step(context, step):
       context.hooks.invoke(br_app.BEFORE_STEP, context, step)


   def after_step(context, step):
       context.hooks.invoke(br_app.AFTER_STEP, context, step)


   def before_tag(context, tag):
       context.hooks.invoke(br_app.BEFORE_TAG, context, tag)


   def after_tag(context, tag):
       context.hooks.invoke(br_app.AFTER_TAG, context, tag)

And under ``features/steps`` add this ``__init__.py`` file:

.. code-block:: python

   # {your_project}/features/steps/__init__.py
   from behave_restful.lang import *

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/behave-restful/behave-restful",
    "name": "behave-restful",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "rest bdd behave gherkin test automation testing",
    "author": "Isaac Rodriguez",
    "author_email": "oss.abantos@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/87/25ab8ba0f6715303416a22cb85d646b750e4076e149c28745f0a3dc554a5/behave-restful-0.4.4.tar.gz",
    "platform": null,
    "description": "\nBehave Restful\n==============\n\n\n.. image:: https://travis-ci.org/behave-restful/behave-restful.svg?branch=master\n   :target: https://travis-ci.org/behave-restful/behave-restful\n   :alt: Build Status\n\n\nBehave Restful is a Behavior Driven Development (BDD) framework based on \n`behave <https://pythonhosted.org/behave/>`_\\ , that implements a language suitable \nto test and validate REST APIs and Services. It leverages the power of the \n`gherkin <https://github.com/cucumber/cucumber/wiki/Gherkin>`_ language to write \nbusiness readable tests that validate the behavior of REST APIs.\n\nAlthough, Behave Restful is implemented in `python <http://www.python.org>`_ and \nuses `behave <https://pythonhosted.org/behave/>`_ as underlying framework, it can \ntest services implemented in any language as easy as:\n\n.. code-block:: gherkin\n\n\n   Feature: API to add a new book to our collection\n       As a user, I want to add a new book to my \"to-read\" collection.\n\n       Scenario: Add a new book to collection.\n           Given a request url http://my.reads/api/books\n               And a request json payload\n                   \"\"\"\n                   {\n                       \"category\": \"reference\",\n                       \"author\": \"Nigel Rees\",\n                       \"title\": \"Sayings of the Century\",\n                       \"price\": 8.95,\n                       \"status\": \"to-read\"\n                   }\n                   \"\"\"\n           When the request sends POST\n           Then the response status is CREATED\n               And the response json matches\n                   \"\"\"\n                   {\n                       \"title\": \"BookObject\",\n                       \"type\": \"object\"\n                       \"properties\": {\n                           \"id\": {\"type\": \"number\"},\n                           \"category\": {\"type\": \"string\"},\n                           \"author\": {\"type\": \"string\"},\n                           \"title\": {\"type\": \"string\"},\n                           \"price\": {\"type\": \"number\"},\n                           \"status\": {\"type\": \"string\", \"enum\": [\"to-read\", \"reading\", \"read\"]}\n                       },\n                       \"required\": [\"id\", \"category\", \"title\"]\n                   }\n                   \"\"\"\n               And the response json at $.id is equal to 100\n               And the response json at $.category is equal to \"reference\"\n               And the response json at $.title is equal to \"Sayings of the Century\"\n\nAs you can see in the example, we send a POST request to the specified url with\na JSON payload, and we can validate the result very easy. First, we verify that\nthe status of the response is CREATED (it succeeds). Then we validate the\nresponse JSON body using the expected `JSON Schema <http://json-schema.org/>`_. \nFinally, we validate specific values in the response using \n`JSONPath <http://goessner.net/articles/JsonPath/>`_\n\nInstallation\n------------\n\nUse pip to install behave-restful in your project\n\n.. code-block::\n\n   pip install behave-restful\n\nSetup\n-----\n\nTo add support for ``behave-restful`` steps in your ``.feature`` files, you need to include behave-restful's environment and step definitions.\n\nYou can do this simply by adding two boilerplate files to your project:\n\nIn the root of your ``features`` directory, add this ``environment.py`` file:\n\n.. code-block:: python\n\n   # {your_project}/features/en/__init__.py\n\n   import os\n\n   import behave_restful.app as br_app\n\n\n   def before_all(context):\n       this_directory = os.path.abspath(os.path.dirname(__file__))\n       br_app.BehaveRestfulApp().initialize_context(context, this_directory)\n       context.hooks.invoke(br_app.BEFORE_ALL, context)\n\n\n   def after_all(context):\n       context.hooks.invoke(br_app.AFTER_ALL, context)\n\n\n   def before_feature(context, feature):\n       context.hooks.invoke(br_app.BEFORE_FEATURE, context, feature)\n\n\n   def after_feature(context, feature):\n       context.hooks.invoke(br_app.AFTER_FEATURE, context, feature)\n\n\n   def before_scenario(context, scenario):\n       context.hooks.invoke(br_app.BEFORE_SCENARIO, context, scenario)\n\n\n   def after_scenario(context, scenario):\n       context.hooks.invoke(br_app.AFTER_SCENARIO, context, scenario)\n\n\n   def before_step(context, step):\n       context.hooks.invoke(br_app.BEFORE_STEP, context, step)\n\n\n   def after_step(context, step):\n       context.hooks.invoke(br_app.AFTER_STEP, context, step)\n\n\n   def before_tag(context, tag):\n       context.hooks.invoke(br_app.BEFORE_TAG, context, tag)\n\n\n   def after_tag(context, tag):\n       context.hooks.invoke(br_app.AFTER_TAG, context, tag)\n\nAnd under ``features/steps`` add this ``__init__.py`` file:\n\n.. code-block:: python\n\n   # {your_project}/features/steps/__init__.py\n   from behave_restful.lang import *\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Implements Gherking language for REST services.",
    "version": "0.4.4",
    "split_keywords": [
        "rest",
        "bdd",
        "behave",
        "gherkin",
        "test",
        "automation",
        "testing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ab011d05123b6b3a9bc0478f14bf9b53ba7bc17315a454a343e5e8c3b59e527",
                "md5": "c2f0c51cff4be7b3905644fbba8db6e9",
                "sha256": "fa40b70f37443dca8526eb6b2c22d510d9c9d629b0d9e52c8806a0c2bb0cb41d"
            },
            "downloads": -1,
            "filename": "behave_restful-0.4.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c2f0c51cff4be7b3905644fbba8db6e9",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 20568,
            "upload_time": "2023-01-13T18:32:23",
            "upload_time_iso_8601": "2023-01-13T18:32:23.263591Z",
            "url": "https://files.pythonhosted.org/packages/2a/b0/11d05123b6b3a9bc0478f14bf9b53ba7bc17315a454a343e5e8c3b59e527/behave_restful-0.4.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b88725ab8ba0f6715303416a22cb85d646b750e4076e149c28745f0a3dc554a5",
                "md5": "a3d0521600f9382b7a55ed93b5f23522",
                "sha256": "3b35841db24f53aa7a83b2eef4e5c81219b395c2e712b7131c44773954c541b9"
            },
            "downloads": -1,
            "filename": "behave-restful-0.4.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a3d0521600f9382b7a55ed93b5f23522",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 16981,
            "upload_time": "2023-01-13T18:32:24",
            "upload_time_iso_8601": "2023-01-13T18:32:24.842536Z",
            "url": "https://files.pythonhosted.org/packages/b8/87/25ab8ba0f6715303416a22cb85d646b750e4076e149c28745f0a3dc554a5/behave-restful-0.4.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-13 18:32:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "behave-restful",
    "github_project": "behave-restful",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "behave-restful"
}
        
Elapsed time: 0.08174s