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

Quickstart

This repository comes with a sample server and Scenarios that can be used for quick hands-on sandboxing.

To run these Scenarios, do the following:

  1. From the examples sub-directory
cd ./examples
  1. Install the dependencies required for the examples
pip install -r requirements.txt
  1. Run the simple server. This will create a simple server that listens on localhost:2396
python3 simple_server.py
  1. Run the ScenarioRunner
python3 scenario_runner.py
  1. If successful, the output should look as follows:
Running scenario Add, Get, and Delete Users defined in examples/scenarios/add_get_delete_users.yaml...
        Running step Reset the server's memory... Success ✅
        Running step Get existing users... Success ✅
        Running step Add a new user... Success ✅
        Running step Get existing users, check that Dave was added... Success ✅
        Running step Delete a user... Success ✅
        Running step Get existing users, check that Charlie was deleted... Success ✅
        Running step Try to delete a user that doesn't exist... Success ✅
Add, Get, and Delete Users Success ✅
Running scenario Sample Service: Health Checks defined in examples/scenarios/healthchecks.yaml...
        Running step Health Check... Success ✅
        Running step Readiness Check... Success ✅
Sample Service: Health Checks Success ✅

Using dasty in your project

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

More examples can be found in the examples subdirectory.

The recommended structure is creating a folder named dasty_tests, containing a sub-folder named scenarios, containing the Scenario YAML files, along with a scenario_runner.py file which looks like:

from dasty_api.ScenarioRunner import ScenarioRunner

if __name__ == "__main__":
    runner = ScenarioRunner("./scenarios")
    runner.run()

Then, the dasty-tests folder should look like:

.
├── scenario_runner.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


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.3.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

dasty_api-0.3.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file dasty_api-0.3.0.tar.gz.

File metadata

  • Download URL: dasty_api-0.3.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for dasty_api-0.3.0.tar.gz
Algorithm Hash digest
SHA256 288ee8daa79157d49a556ca8ce295b0b15d3cdfda47d5cf7567173eaef04226c
MD5 cb0346496cc13ec2e9a126235e909dd0
BLAKE2b-256 643ee744824fde01c3f87af328fd49c7a938fc1dfc6fcfc86dc93eed7b972af9

See more details on using hashes here.

File details

Details for the file dasty_api-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dasty_api-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for dasty_api-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56e757babde1e47daedf833fa045a4e1ae125cdd2b0c729654cd58d4bc49df8c
MD5 273e9e00bd305a403297e65ad1893a0e
BLAKE2b-256 69587fa76a6a65a246ba5f3447e62b912782ffe3fa1f75c72b59e2f984df316c

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