Skip to main content

Seekret's library for API testing runtime

Project description

Seekret API testing runtime

The seekret.apitest package contains runtime functions and tools intended to ease API testing.

The seekret.apitest package is not used directly, but is referenced within tavern tests generated by Seekret.

Quickstart

First, install tavern and seekret.apitest: pip install tavern seekret.apitest

Now, in order to run a test:

  1. Store one or more generated tavern tests from the Seekret website in a directory.
  2. Copy the configuration file you received from Seekret to the same directory.

Your test directory should look like this:

/testdir
|-- test_1.tavern.yaml
|-- test_2.tavern.yaml
|-- ...
|-- config.yaml

After your test directory is set up, run pytest --tavern-global-cfg config.yaml.

Tavern will collect all test_*.tavern.yaml files and run the described tests.

Understanding the configuration and generated tests

Tavern tests generated by Seekret use common variables which are expected to be set using an external configuration. This currently includes the host of the target servers and the authorization settings.

Example generated test file:

# test_1.tavern.yaml

stages:
  - name: POST /user
    request:
      headers:
        $ext:
          function: seekret.apitest:add_auth_in_headers
          # This section defines that the headers are extended with
          # the result of the `add_auth_in_headers` function.
          # The `add_auth_in_headers` function uses Seekret-format
          # authorization settings defined in the configuration file
          # in the "user" variable.
          extra_kwargs:
            auth_data: !force_format_include '{user.data}'
            auth_type: '{user.type}'
      json:
        # Randomized body values, created during test generation.
        email: jenkinsjennifer@king.com
        name: vrdyin
        photo: https://hernandez.biz/
      method: POST
      url: '{host}/user' # The "host" variable from the configuration file.
    response:
      save:
        json:
          # Later tests can use the `userId` value from this response
          # by specifying this variable name.
          saved_0_responseBody_userId: userId
      status_code:
        - 200

Example configuration file:

name: Global test configuration
description: |
  Global configuration for running the tavern tests.

variables:
  host: http://example.com
  user:
    type: bearer
    data:
      token: <Preconfigured API token for the test user>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

seekret.apitest-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file seekret.apitest-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: seekret.apitest-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for seekret.apitest-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e6523577d43d84e566fd4ca7b33a55284e619565c1213eaa25984e2ed4c5c6b
MD5 7b55d036eab2fcc907a052964caae738
BLAKE2b-256 247d2f9263cdf205fcfbf891eb6e8958375c6a292559e10aed24e8335d892a6b

See more details on using hashes here.

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