Skip to main content

Declarative API Scenario Testing in YAML - Easily define and run API tests using YAML.

Project description

Dasty: Declarative API Scenario Testing in YAML

Dasty is a Python package designed to simplify the process of testing APIs by allowing tests to be defined declaratively in YAML format. This approach enables easy-to-write, easy-to-read API test scenarios, making API testing more accessible and maintainable.

Features

  • Declarative Syntax: Define API tests in a simple, human-readable YAML format.
  • Flexible Test Scenarios: Support various HTTP methods and validations.
  • Easy Variable Substitution: Define and use variables within your YAML test scenarios.

Installation

To install Dasty, simply use pip:

pip install dasty_api

Usage

Dasty allows you to define your API test scenarios in YAML files. Here's a basic example:

name: "Users Service: Health Checks"
description:
  - "Health checks for the Users service"
variables:
  BASE_URL: "http://127.0.0.1:8003/api/v1/"
steps:
  - name: "Health Check"
    method: "GET"
    url: "${BASE_URL}/healthz"
    expected_status_code: 200
  - name: "Readiness Check"
    method: "GET"
    url: "${BASE_URL}/readyz"
    expected_status_code: 200

The recommended structure is creating a folder named dasty_tests, containing a sub-folder named scenarios, along with a main.py file which looks like:

from dasty_api.dasty import YAMLScenario
import pathlib
import sys

if __name__ == "__main__":
    # Use the provided file path if one is provided
    if len(sys.argv) > 1:
        filepath = sys.argv[1]
        scenario = YAMLScenario(filepath=filepath)
        scenario.run()
    # Otherwise, run all the scenarios in the scenarios directory
    else:
        scenario_directory = pathlib.Path("./scenarios")
        # Get each file name in the target directory
        scenario_filepaths = [str(path) for path in scenario_directory.glob("*.yaml")]
        # Create a YAML scenario for each file
        scenarios = [YAMLScenario(filepath=filepath) for filepath in scenario_filepaths]
        for scenario in scenarios:
            scenario.run()

Then, the dasty-tests folder should look like:

.
├── main.py
└── scenarios
    ├── ...
    └── sample_scenario.yaml

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

dasty_api-0.2.0.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

dasty_api-0.2.0-py3-none-any.whl (9.0 kB view hashes)

Uploaded Python 3

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