Skip to main content

Provides testing for JSON APIs with Behave

Project description

Build Status Version

Provides testing for JSON APIs with Behave [1]

Requires Python 3.11 or newer.

Installation

uv add behave-web-api

Import steps in your features/steps/__init__.py

from behave_web_api.steps import *

So you can use the steps in your feature files

Feature: Doing http requests

  Scenario: Send text body and headers
    Given I set header "X-My-Header" with value "Something"
    And I set header "Content-Type" with value "application/json"
    When I send a POST request to "/requests/echo" with body:
    """
    {
        "a": 1,
        "b": "",
        "c": "0101",
        "d": "[01]+"
    }
    """
    Then the response code should be 200
    And the response should contain json:
    """
        {
            "headers": {
                "X-My-Header": "Something"
            },
            "body": {
                "a": "<is_number>",
                "b": "%.*%",
                "c": "%[01]+%",
                "d": "[01]+"
            }
        }
    """

  Scenario: Send file using variables and environment variables
    Given I set the variable "DATA_DIR" with value "$PWD/features/data"
    And I attach the file "$DATA_DIR/favicon.ico" as "upload"
    When I send a POST request to "/requests/echo"
    Then the response code should be 200
    And print response

And run using BASE_URL environment variable:

BASE_URL=localhost:5000 behave features/requests.feature

Available Steps

  • Given I set variable “{}” with value “{}”

  • Given I set header “{}” with value “{}”

  • Given I attach the file “{}” as “{}”

  • When I send a {} request to “{}” with body:

  • When I send a {} request to “{}” with values:

  • When I send a {} request to “{}”

  • Then the response code should be {}

  • Then the response should contain json:

  • Then the response should contain text:

  • Then print response

Acknowledgments

The REST steps are based on Behat WebApiExtension [2]

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

behave_web_api-2.3.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

behave_web_api-2.3.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file behave_web_api-2.3.0.tar.gz.

File metadata

  • Download URL: behave_web_api-2.3.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for behave_web_api-2.3.0.tar.gz
Algorithm Hash digest
SHA256 5eb505a3a334475d4ceb6483c53c7061e80321d99cf44fd14afb586be8cfc8f6
MD5 974ae4a647b0791486df271386cebf2b
BLAKE2b-256 9d8d6fa3f7abe90713257821563ffa53180a17502ca24f1fa4ffcb4667b52348

See more details on using hashes here.

File details

Details for the file behave_web_api-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: behave_web_api-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for behave_web_api-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf954e0004d38c9d65bdabdc5f3e0fd4997817422ae59d11dad90799f8d7ac27
MD5 b38d97a928b7e566c584d52f399fba4e
BLAKE2b-256 9a9c71b89328ba09de8bb7ba57cb17efc3bfb45492298d870adcbfa6dbaa36cd

See more details on using hashes here.

Supported by

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