Metadata-Version: 2.1
Name: dasty-api
Version: 0.2.0
Summary: Declarative API Scenario Testing in YAML - Easily define and run API tests using YAML.
Home-page: https://github.com/rohitkochhar/dasty
Author: Rohit Singh
Author-email: rsingh.yaml@gmail.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: certifi==2023.11.17
Requires-Dist: charset-normalizer==3.3.2
Requires-Dist: idna==3.6
Requires-Dist: PyYAML==6.0.1
Requires-Dist: requests==2.31.0
Requires-Dist: urllib3==2.1.0

# 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:

```bash
pip install dasty_api
```

## Usage

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

```yaml
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:

```python
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
```
