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
Once main.py is executed, the output should look as follows:
╰─ python3 main.py
Running scenario Users Service: Health Checks defined in scenarios/healthcheck_users.yaml...
Running step Health Check... Success ✅
Running step Readiness Check... Success ✅
Users Service: Health Checks Success ✅
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dasty_api-0.2.6.tar.gz.
File metadata
- Download URL: dasty_api-0.2.6.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96f4df70b3e2db4ad2b1217f4d9686ac5de82c559a44d6c44ee4a693b69cecda
|
|
| MD5 |
352a6960aa35d51ce3cb2de69ffb4c16
|
|
| BLAKE2b-256 |
65251bd49c60c86fc7a18be39b21e73bf45e8d6f81d63bfa0fc373aae8b54078
|
File details
Details for the file dasty_api-0.2.6-py3-none-any.whl.
File metadata
- Download URL: dasty_api-0.2.6-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442cc1e53431603f6807753dd429230b5c2a1b27dfcce68372418b0f1af934fc
|
|
| MD5 |
391f0de275a5b81a58e9ca237d24857b
|
|
| BLAKE2b-256 |
406a0d1fe814e1b688d1c4ccb328aeee7a2daa47cfde7b154809fd6939505595
|