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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dasty_api-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 131451262295340f339becef25e58e94870a1207dd75b5171a614c21528bcb6f |
|
MD5 | 8b6cd2b7454c7579ec8d9ee9146c4fc0 |
|
BLAKE2b-256 | ca155ece1f297c26839b419c7d5c1bb2d26b20871e95cb52ef4956072dd264d2 |