Skip to main content

Web API testing for haas

Project description

Build status Coverage status

usagi is a plugin for haas that adds support for discovering Web API test cases descibed in YAML.

usagi requires haas v0.6.0 or later.

Current Features

  • Describe web API tests using YAML.

  • Template URLs to avoid repeating items.

  • Variables and target hostname can be provided by environment variables.

  • YAML format contains multiple test cases.

  • Each test case is a grouping of related tests.

  • Make flexible assertions about the server’s response.

  • Contribute web API test runner functionality through plugins.

  • Assert that the SHA256 of the response body matches an expected value.

  • Filter JSON response bodies before comparison using jq filter syntax:


  • Var loaders

    • Load from environment

    • Template string based on other vars

    • Load from file, either plaintext or JSON

  • Assertions

    • Assert status code

    • Assert header is present or matches value or regexp


  • Add more assertions!

Test config format

  • version: Currently required, but unverified (we are at v0.1.0.devN, after all).

  • config: Common test case configuration.

    • host: The name (or IP) of the host to test.

      • Can come from env, template, file, like vars.

    • scheme: The scheme (http, https) to use to connect to host

    • vars: Common variable definitions for all test cases; formatted as a dictionary of var name to type and value.

      • Simple string vars are allowed.

      • Others are specified as a dictionary with key type to determine how to load.

  • cases: Collection of test cases. Each case contains multiple tests

    • name: The name of the test case

    • tests: Collection of individual tests

      • name: The name of the test

      • url: The URI/path relative to host against which the test will be executed.

      • method: The HTTP method to use for the test.

      • assertions: List of assertions to make about the test.

Example Test

  version: '1.0'

    # Host is loaded as an environment variable
      type: env
      env: TEST_HOSTNAME

      # Simple string var
      api_root: "/api/v1/json"

      # Template var
        type: template
        template: "{api_root}/metadata"

      # Variable loaded as JSON from file
        type: file
        file: some_file.json
        format: json

    - name: "Basic"
        - name: "Test root URL"
          url: "/"
            - name: status_code
              expected: 200
            - name: header
              header: Content-Type
              value: text/plain

    - name: "A case"
        - name: "Authentication failure"
            type: template
            template: "{metadata}/auth/required"
            method: GET
              Content-Type: application/json
            - name: status_code
              expected: 401
            - name: header
              header: WWW-Authenticate
              regexp: "Basic realm=.*"
        - name: "POST json"
            type: template
            template: "{metadata}/post"
            method: POST
              format: json
              lookup-var: false
                some: ["json-compatible", "structure"]
            - name: status_code
              expected: 204

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

usagi-0.3.1.tar.gz (18.7 kB view hashes)

Uploaded source

Built Distribution

usagi-0.3.1-py2.py3-none-any.whl (28.2 kB view hashes)

Uploaded py2 py3

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